]> arthur.barton.de Git - netatalk.git/blobdiff - include/atalk/errchk.h
Fix unnamed union inside struct
[netatalk.git] / include / atalk / errchk.h
index cac135703a19155c987aad365249bd4e824f4541..ccc66eb6f4ac1a9ae7ff52a57c3291d219e3ed02 100644 (file)
 #define ERRCHECK_H
 
 #define EC_INIT int ret = 0
+#define EC_STATUS(a) ret = (a)
+#define EC_EXIT_STATUS(a) do { ret = (a); goto cleanup; } while (0)
+#define EC_FAIL do { ret = -1; goto cleanup; } while (0)
+#define EC_FAIL_LOG(a, ...)                     \
+    do {               \
+        LOG(log_error, logtype_default, a, __VA_ARGS__);   \
+        ret = -1;      \
+        goto cleanup;  \
+    } while (0)
 #define EC_CLEANUP cleanup
 #define EC_EXIT return ret
 
 /* 
+ * Check out doc/DEVELOPER for more infos.
+ *
  * We have these macros:
- * EC_ZERO_PRINT
- * EC_ZERO
- * EC_NEG1_PRINT
- * EC_NEG1
- * EC_NULL_PRINT
- * EC_NULL
+ * EC_ZERO, EC_ZERO_LOG, EC_ZERO_LOGSTR, EC_ZERO_LOG_ERR, EC_ZERO_CUSTOM
+ * EC_NEG1, EC_NEG1_LOG, EC_NEG1_LOGSTR, EC_NEG1_LOG_ERR, EC_NEG1_CUSTOM
+ * EC_NULL, EC_NULL_LOG, EC_NULL_LOGSTR, EC_NULL_LOG_ERR, EC_NULL_CUSTOM
+ *
+ * A boileplate function template is:
+
+   int func(void)
+   {
+       EC_INIT;
+
+       ...your code here...
+
+       EC_STATUS(0);
+
+   EC_CLEANUP:
+       EC_EXIT;
+   }
  */
 
 /* check for return val 0 which is ok, every other is an error, prints errno */
-#define EC_ZERO_PRINT(a) \
-    do { \
-        if ((a) != 0) { \
-            LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
-            ret = -1; \
-            goto cleanup; \
-        } \
+#define EC_ZERO_LOG(a)                                                  \
+    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 */
-#define EC_ZERO(a) \
-    do { \
-        if ((a) != 0) { \
-            ret = -1; \
-            goto cleanup; \
-        } \
+#define EC_ZERO_LOGSTR(a, b, ...)                                       \
+    do {                                                                \
+        if ((a) != 0) {                                                 \
+            LOG(log_error, logtype_default, b, __VA_ARGS__);            \
+            ret = -1;                                                   \
+            goto cleanup;                                               \
+        }                                                               \
+    } while (0)
+
+#define EC_ZERO_LOG_ERR(a, b)                                           \
+    do {                                                                \
+        if ((a) != 0) {                                                 \
+            LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
+            ret = (b);                                                  \
+            goto cleanup;                                               \
+        }                                                               \
+    } while (0)
+
+#define EC_ZERO(a)                              \
+    do {                                        \
+        if ((a) != 0) {                         \
+            ret = -1;                           \
+            goto cleanup;                       \
+        }                                       \
+    } while (0)
+
+#define EC_ZERO_ERR(a,b )                       \
+    do {                                        \
+        if ((a) != 0) {                         \
+            ret = b;                            \
+            goto cleanup;                       \
+        }                                       \
     } while (0)
 
 /* check for return val 0 which is ok, every other is an error, prints errno */
-#define EC_NEG1_PRINT(a) \
-    do { \
-        if ((a) == -1) { \
-            LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
-            ret = -1; \
-            goto cleanup; \
-        } \
+#define EC_NEG1_LOG(a)                                                  \
+    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 */
-#define EC_NEG1(a) \
-    do { \
-        if ((a) == -1) { \
-            ret = -1; \
-            goto cleanup; \
-        } \
+#define EC_NEG1_LOGSTR(a, b, ...)                               \
+    do {                                                        \
+        if ((a) == -1) {                                        \
+            LOG(log_error, logtype_default, b, __VA_ARGS__);    \
+            ret = -1;                                           \
+            goto cleanup;                                       \
+        }                                                       \
+    } while (0)
+
+#define EC_NEG1_LOG_ERR(a, b)                                           \
+    do {                                                                \
+        if ((a) == -1) {                                                \
+            LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
+            ret = b;                                                    \
+            goto cleanup;                                               \
+        }                                                               \
+    } while (0)
+
+#define EC_NEG1(a)                              \
+    do {                                        \
+        if ((a) == -1) {                        \
+            ret = -1;                           \
+            goto cleanup;                       \
+        }                                       \
     } while (0)
 
 /* check for return val != NULL, prints errno */
-#define EC_NULL_PRINT(a) \
-    do { \
-        if ((a) == NULL) { \
-            LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
-            ret = -1; \
-            goto cleanup; \
-        } \
+#define EC_NULL_LOG(a)                                                  \
+    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 */
-#define EC_NULL(a) \
-    do { \
-        if ((a) == NULL) { \
-            ret = -1; \
-            goto cleanup; \
+#define EC_NULL_LOGSTR(a, b, ...)                                       \
+    do {                                                                \
+        if ((a) == NULL) {                                              \
+            LOG(log_error, logtype_default, b , __VA_ARGS__);           \
+            ret = -1;                                                   \
+            goto cleanup;                                               \
         } \
     } while (0)
 
+#define EC_NULL_LOG_ERR(a, b)                                           \
+    do {                                                                \
+        if ((a) == NULL) {                                              \
+            LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
+            ret = b;                                                    \
+            goto cleanup;                                               \
+        }                                                               \
+    } while (0)
+
+#define EC_NULL(a)                              \
+    do {                                        \
+        if ((a) == NULL) {                      \
+            ret = -1;                           \
+            goto cleanup;                       \
+        }                                       \
+    } while (0)
+
 #endif /* ERRCHECK_H */