]> arthur.barton.de Git - netatalk.git/commitdiff
Error checking macros
authorFrank Lahm <franklahm@googlemail.com>
Mon, 27 Sep 2010 20:52:25 +0000 (22:52 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 27 Sep 2010 20:52:25 +0000 (22:52 +0200)
include/atalk/errcheck.h [new file with mode: 0644]

diff --git a/include/atalk/errcheck.h b/include/atalk/errcheck.h
new file mode 100644 (file)
index 0000000..cac1357
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+   Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+ */
+
+#ifndef ERRCHECK_H
+#define ERRCHECK_H
+
+#define EC_INIT int ret = 0
+#define EC_CLEANUP cleanup
+#define EC_EXIT return ret
+
+/* 
+ * We have these macros:
+ * EC_ZERO_PRINT
+ * EC_ZERO
+ * EC_NEG1_PRINT
+ * EC_NEG1
+ * EC_NULL_PRINT
+ * EC_NULL
+ */
+
+/* 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; \
+        } \
+    } 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; \
+        } \
+    } 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; \
+        } \
+    } 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; \
+        } \
+    } 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; \
+        } \
+    } while (0)
+
+/* check for return val != NULL */
+#define EC_NULL(a) \
+    do { \
+        if ((a) == NULL) { \
+            ret = -1; \
+            goto cleanup; \
+        } \
+    } while (0)
+
+#endif /* ERRCHECK_H */