Changeset 3090715 in mainline for uspace/lib/c
- Timestamp:
- 2010-11-07T21:16:56Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d0d06a
- Parents:
- 9ce7eb5 (diff), 9ee9d5d5 (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. - Location:
- uspace/lib/c
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/measured_strings.c
r9ce7eb5 r3090715 41 41 #include <unistd.h> 42 42 #include <errno.h> 43 #include <err.h>44 43 #include <async.h> 45 44 … … 135 134 size_t count) 136 135 { 137 ERROR_DECLARE;138 139 136 size_t *lengths; 140 137 size_t index; … … 142 139 char *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 … … 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; … … 251 250 int measured_strings_reply(const measured_string_ref strings, size_t count) 252 251 { 253 ERROR_DECLARE;254 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 } … … 313 314 size_t count) 314 315 { 315 ERROR_DECLARE;316 317 316 size_t *lengths; 318 317 size_t index; 319 318 char *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 … … 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; … … 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 } -
uspace/lib/c/include/adt/generic_char_map.h
r9ce7eb5 r3090715 40 40 #include <unistd.h> 41 41 #include <errno.h> 42 #include <err.h>43 42 44 43 #include <adt/char_map.h> … … 85 84 type *value) \ 86 85 { \ 87 ERROR_DECLARE; \86 int rc; \ 88 87 int index; \ 89 88 if (!name##_is_valid(map)) \ … … 92 91 if (index < 0) \ 93 92 return index; \ 94 if (ERROR_OCCURRED(char_map_add(&map->names, name, length,\95 index))) { \93 rc = char_map_add(&map->names, name, length, index); \ 94 if (rc != EOK) { \ 96 95 name##_items_exclude_index(&map->values, index); \ 97 return ERROR_CODE; \96 return rc; \ 98 97 } \ 99 98 return EOK; \ … … 141 140 int name##_initialize(name##_ref map) \ 142 141 { \ 143 ERROR_DECLARE; \142 int rc; \ 144 143 if (!map) \ 145 144 return EINVAL; \ 146 ERROR_PROPAGATE(char_map_initialize(&map->names)); \ 147 if (ERROR_OCCURRED(name##_items_initialize(&map->values))) { \ 145 rc = char_map_initialize(&map->names); \ 146 if (rc != EOK) \ 147 return rc; \ 148 rc = name##_items_initialize(&map->values); \ 149 if (rc != EOK) { \ 148 150 char_map_destroy(&map->names); \ 149 return ERROR_CODE; \151 return rc; \ 150 152 } \ 151 153 map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE; \ -
uspace/lib/c/include/err.h
r9ce7eb5 r3090715 37 37 38 38 #include <stdio.h> 39 #include <errno.h>40 41 #ifdef CONFIG_DEBUG42 #include <str_error.h>43 #endif44 39 45 40 #define errx(status, fmt, ...) { \ … … 48 43 } 49 44 50 51 /** An actual stored error code. */52 #define ERROR_CODE error_check_return_value53 54 /** An error processing routines declaration.55 *56 * This has to be declared in the block where the error processing57 * is desired.58 */59 #define ERROR_DECLARE int ERROR_CODE60 61 /** Store the value as an error code and checks if an error occurred.62 *63 * @param[in] value The value to be checked. May be a function call.64 * @return False if the value indicates success (EOK).65 * @return True otherwise.66 */67 #ifdef CONFIG_DEBUG68 69 #define ERROR_OCCURRED(value) \70 (((ERROR_CODE = (value)) != EOK) && \71 ({ \72 fprintf(stderr, "libsocket error at %s:%d (%s)\n", \73 __FILE__, __LINE__, str_error(ERROR_CODE)); \74 1; \75 }))76 77 #else78 79 #define ERROR_OCCURRED(value) ((ERROR_CODE = (value)) != EOK)80 81 #endif82 83 #define ERROR_NONE(value) !ERROR_OCCURRED((value))84 85 /** Error propagation86 *87 * Check if an error occurred and immediately exit the actual88 * function returning the error code.89 *90 * @param[in] value The value to be checked. May be a function call.91 *92 */93 94 #define ERROR_PROPAGATE(value) \95 if (ERROR_OCCURRED(value)) \96 return ERROR_CODE97 98 45 #endif 99 46 100 47 /** @} 101 48 */ 49
Note:
See TracChangeset
for help on using the changeset viewer.