Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/err.h

    r47b7006 rc5b59ce  
    3737
    3838#include <stdio.h>
     39#include <errno.h>
    3940
    40 #define errx(status, fmt, ...) \
    41         do { \
    42                 printf((fmt), ##__VA_ARGS__); \
    43                 exit(status); \
    44         } while (0)
     41#ifdef CONFIG_DEBUG
     42#include <str_error.h>
     43#endif
     44
     45#define errx(status, fmt, ...) { \
     46        printf((fmt), ##__VA_ARGS__); \
     47        _exit(status); \
     48}
     49
     50
     51/** An actual stored error code.  */
     52#define ERROR_CODE  error_check_return_value
     53
     54/** An error processing routines declaration.
     55 *
     56 * This has to be declared in the block where the error processing
     57 * is desired.
     58 */
     59#define ERROR_DECLARE  int ERROR_CODE
     60
     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_DEBUG
     68
     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#else
     78
     79#define ERROR_OCCURRED(value)   ((ERROR_CODE = (value)) != EOK)
     80
     81#endif
     82
     83#define ERROR_NONE(value)       !ERROR_OCCURRED((value))
     84
     85/** Error propagation
     86 *
     87 * Check if an error occurred and immediately exit the actual
     88 * 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_CODE
    4597
    4698#endif
Note: See TracChangeset for help on using the changeset viewer.