netatalk: errchk.h File Reference

netatalk 4.5.1
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
errchk.h File Reference

Error checking macros. More...

Go to the source code of this file.

## Macros
#define | EC_INIT int ret = 0
#define | EC_STATUS(a)
#define | EC_EXIT_STATUS(a)
#define | EC_FAIL do { ret = -1; goto cleanup; } while (0)
#define | EC_FAIL_LOG(...)
#define | EC_CLEANUP cleanup
#define | EC_EXIT return ret
#define | EC_ZERO_LOG(a)
#define | EC_ZERO_LOGSTR(a, b, ...)
#define | EC_ZERO_LOG_ERR(a, b)
#define | EC_ZERO(a)
#define | EC_ZERO_ERR(a, b)
#define | EC_NEG1_LOG(a)
#define | EC_NEG1_LOGSTR(a, b, ...)
#define | EC_NEG1_LOG_ERR(a, b)
#define | EC_NEG1(a)
#define | EC_NULL_LOG(a)
#define | EC_NULL_LOGSTR(a, b, ...)
#define | EC_NULL_LOG_ERR(a, b)
#define | EC_NULL(a)

## Detailed Description

Error checking macros.

See also
  ./doc/developer/developer.md

We have these macros:

EC_ZERO, EC_ZERO_LOG, EC_ZERO_LOGSTR, EC_ZERO_LOG_ERR
EC_NEG1, EC_NEG1_LOG, EC_NEG1_LOGSTR, EC_NEG1_LOG_ERR
EC_NULL, EC_NULL_LOG, EC_NULL_LOGSTR, EC_NULL_LOG_ERR
EC_NEG1_LOG
#define EC_NEG1_LOG(a)
Definition errchk.h:105
EC_ZERO_LOG_ERR
#define EC_ZERO_LOG_ERR(a, b)
Definition errchk.h:79
EC_NULL_LOG
#define EC_NULL_LOG(a)
Definition errchk.h:141
EC_NEG1_LOG_ERR
#define EC_NEG1_LOG_ERR(a, b)
Definition errchk.h:123
EC_ZERO
#define EC_ZERO(a)
Definition errchk.h:88
EC_NULL_LOGSTR
#define EC_NULL_LOGSTR(a, b,...)
Definition errchk.h:150
EC_NEG1_LOGSTR
#define EC_NEG1_LOGSTR(a, b,...)
Definition errchk.h:114
EC_NEG1
#define EC_NEG1(a)
Definition errchk.h:132
EC_ZERO_LOGSTR
#define EC_ZERO_LOGSTR(a, b,...)
Definition errchk.h:70
EC_ZERO_LOG
#define EC_ZERO_LOG(a)
Definition errchk.h:61
EC_NULL_LOG_ERR
#define EC_NULL_LOG_ERR(a, b)
Definition errchk.h:159
EC_NULL
#define EC_NULL(a)
Definition errchk.h:168

A boileplate function template is:

int func(void)
{
EC_INIT;
...your code here...
EC_STATUS(0);
EC_CLEANUP:
EC_EXIT;
}
EC_CLEANUP
#define EC_CLEANUP
Definition errchk.h:28
EC_INIT
#define EC_INIT
Definition errchk.h:18
EC_EXIT
#define EC_EXIT
Definition errchk.h:29
EC_STATUS
#define EC_STATUS(a)
Definition errchk.h:19

## Macro Definition Documentation

## ◆ EC_CLEANUP

#define EC_CLEANUP cleanup

## ◆ EC_EXIT

#define EC_EXIT return ret

## ◆ EC_EXIT_STATUS

#define EC_EXIT_STATUS | ( |  | a | ) |

Value:
do { ret = (a); goto cleanup; } while (0)

## ◆ EC_FAIL

#define EC_FAIL do { ret = -1; goto cleanup; } while (0)

## ◆ EC_FAIL_LOG

#define EC_FAIL_LOG | ( |  | ... | ) |

Value:
do { \
LOG(log_error, logtype_default, __VA_ARGS__); \
ret = -1; \
goto cleanup; \
} while (0)
logtype_default
@ logtype_default
Definition logger.h:34
log_error
@ log_error
Definition logger.h:20

## ◆ EC_INIT

#define EC_INIT int ret = 0

## ◆ EC_NEG1

#define EC_NEG1 | ( |  | a | ) |

Value:
do { \
if ((a) == -1) { \
ret = -1; \
goto cleanup; \
} \
} while (0)

## ◆ EC_NEG1_LOG

#define EC_NEG1_LOG | ( |  | a | ) |

Value:
do { \
if ((a) == -1) { \
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
ret = -1; \
goto cleanup; \
} \
} while (0)

check for return val 0 which is ok, every other is an error, prints errno

## ◆ EC_NEG1_LOG_ERR

#define EC_NEG1_LOG_ERR | ( |  | a,
|  |  | b )

Value:
do { \
if ((a) == -1) { \
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
ret = b; \
goto cleanup; \
} \
} while (0)

## ◆ EC_NEG1_LOGSTR

#define EC_NEG1_LOGSTR | ( |  | a,
|  |  | b,
|  |  | ... )

Value:
do { \
if ((a) == -1) { \
LOG(log_error, logtype_default, b, __VA_ARGS__); \
ret = -1; \
goto cleanup; \
} \
} while (0)

## ◆ EC_NULL

#define EC_NULL | ( |  | a | ) |

Value:
do { \
if ((a) == NULL) { \
ret = -1; \
goto cleanup; \
} \
} while (0)
NULL
#define NULL
Definition utf8util.c:47

## ◆ EC_NULL_LOG

#define EC_NULL_LOG | ( |  | a | ) |

Value:
do { \
if ((a) == NULL) { \
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
ret = -1; \
goto cleanup; \
} \
} while (0)

check for return val != NULL, prints errno

## ◆ EC_NULL_LOG_ERR

#define EC_NULL_LOG_ERR | ( |  | a,
|  |  | b )

Value:
do { \
if ((a) == NULL) { \
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
ret = b; \
goto cleanup; \
} \
} while (0)

## ◆ EC_NULL_LOGSTR

#define EC_NULL_LOGSTR | ( |  | a,
|  |  | b,
|  |  | ... )

Value:
do { \
if ((a) == NULL) { \
LOG(log_error, logtype_default, b , __VA_ARGS__); \
ret = -1; \
goto cleanup; \
} \
} while (0)

## ◆ EC_STATUS

#define EC_STATUS | ( |  | a | ) |

Value:
ret = (a)

## ◆ EC_ZERO

#define EC_ZERO | ( |  | a | ) |

Value:
do { \
if ((a) != 0) { \
ret = -1; \
goto cleanup; \
} \
} while (0)

## ◆ EC_ZERO_ERR

#define EC_ZERO_ERR | ( |  | a,
|  |  | b )

Value:
do { \
if ((a) != 0) { \
ret = b; \
goto cleanup; \
} \
} while (0)

## ◆ EC_ZERO_LOG

#define EC_ZERO_LOG | ( |  | a | ) |

Value:
do { \
if ((a) != 0) { \
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
ret = -1; \
goto cleanup; \
} \
} while (0)

check for return val 0 which is ok, every other is an error, prints errno

## ◆ EC_ZERO_LOG_ERR

#define EC_ZERO_LOG_ERR | ( |  | a,
|  |  | b )

Value:
do { \
if ((a) != 0) { \
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
ret = (b); \
goto cleanup; \
} \
} while (0)

## ◆ EC_ZERO_LOGSTR

#define EC_ZERO_LOGSTR | ( |  | a,
|  |  | b,
|  |  | ... )

Value:
do { \
if ((a) != 0) { \
LOG(log_error, logtype_default, b, __VA_ARGS__); \
ret = -1; \
goto cleanup; \
} \
} while (0)