Changeset d2b1040 in mainline for uspace/lib/c/generic/adt/measured_strings.c
- Timestamp:
- 2010-10-27T20:33:51Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f4c8a83f
- Parents:
- 6067284
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/measured_strings.c
r6067284 rd2b1040 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); … … 192 191 (*strings)[index].value = next; 193 192 next += lengths[index]; 194 *next = '\0'; 195 ++next; 193 *next++ = '\0'; 196 194 } else { 197 195 (*strings)[index].value = NULL; … … 221 219 222 220 length = 0; 223 for (index = 0; index < count; ++ index) {221 for (index = 0; index < count; index++) { 224 222 lengths[index] = strings[index].length; 225 223 length += lengths[index] + 1; … … 262 260 return ENOMEM; 263 261 264 if ( (!async_data_read_receive(&callid, &length)) ||262 if (!async_data_read_receive(&callid, &length) || 265 263 (length != sizeof(size_t) * (count + 1))) { 266 264 free(lengths); 267 265 return EINVAL; 268 266 } 269 if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, 270 sizeof(size_t) * (count + 1)))) { 267 if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) { 271 268 free(lengths); 272 269 return ERROR_CODE; … … 274 271 free(lengths); 275 272 276 for (index = 0; index < count; ++ index) {273 for (index = 0; index < count; index++) { 277 274 if (strings[index].length > 0) { 278 if ((!async_data_read_receive(&callid, &length))||275 if (!async_data_read_receive(&callid, &length) || 279 276 (length != strings[index].length)) { 280 277 return EINVAL; … … 317 314 char *next; 318 315 319 if ((phone < =0) || (!strings) || (!data) || (count <= 0))316 if ((phone < 0) || (!strings) || (!data) || (count <= 0)) 320 317 return EINVAL; 321 318 … … 331 328 332 329 *data = malloc(lengths[count]); 333 if (! (*data)) {330 if (!*data) { 334 331 free(lengths); 335 332 return ENOMEM; … … 338 335 *strings = (measured_string_ref) malloc(sizeof(measured_string_t) * 339 336 count); 340 if (! (*strings)) {337 if (!*strings) { 341 338 free(lengths); 342 339 free(*data); … … 345 342 346 343 next = *data; 347 for (index = 0; index < count; ++ index) {344 for (index = 0; index < count; index++) { 348 345 (*strings)[index].length = lengths[index]; 349 346 if (lengths[index] > 0) { … … 352 349 (*strings)[index].value = next; 353 350 next += lengths[index]; 354 *next = '\0'; 355 ++ next; 351 *next++ = '\0'; 356 352 } else { 357 353 (*strings)[index].value = NULL; … … 386 382 size_t index; 387 383 388 if ((phone < =0) || (!strings) || (count <= 0))384 if ((phone < 0) || (!strings) || (count <= 0)) 389 385 return EINVAL; 390 386 … … 401 397 free(lengths); 402 398 403 for (index = 0; index < count; ++index) {399 for (index = 0; index < count; index++) { 404 400 if (strings[index].length > 0) { 405 401 ERROR_PROPAGATE(async_data_write_start(phone,
Note:
See TracChangeset
for help on using the changeset viewer.