cctools
catch.h
1 /*
2  * Copyright (C) 2014- The University of Notre Dame
3  * This software is distributed under the GNU General Public License.
4  * See the file COPYING for details.
5  */
6 
7 #ifndef CATCH_H
8 #define CATCH_H
9 
10 #include <errno.h>
11 #include <string.h>
12 
13 #define THROW_QUIET(e) \
14  do {\
15  rc = (e);\
16  goto out;\
17  } while (0)
18 
19 #define CATCH(expr) \
20  do {\
21  rc = (expr);\
22  if (rc) {\
23  debug(D_DEBUG, "%s: %s:%d[%s] error: %d `%s'", __func__, __FILE__, __LINE__, CCTOOLS_SOURCE, rc, strerror(rc));\
24  goto out;\
25  }\
26  } while (0)
27 
28 #define CATCHUNIX(expr) \
29  do {\
30  rc = (expr);\
31  if (rc == -1) {\
32  rc = errno;\
33  debug(D_DEBUG, "%s: %s:%d[%s] unix error: -1 (errno = %d) `%s'", __func__, __FILE__, __LINE__, CCTOOLS_SOURCE, rc, strerror(rc));\
34  goto out;\
35  }\
36  } while (0)
37 
38 #define CATCHUNIXIGNORE(expr,err) \
39  do {\
40  rc = (expr);\
41  if (rc == -1 && errno != err) {\
42  rc = errno;\
43  debug(D_DEBUG, "%s: %s:%d[%s] unix error: -1 (errno = %d) `%s'", __func__, __FILE__, __LINE__, CCTOOLS_SOURCE, rc, strerror(rc));\
44  goto out;\
45  }\
46  } while (0)
47 
48 #define RCUNIX(rc) (rc == 0 ? 0 : (errno = rc, -1))
49 
50 #endif
51 
52 /* vim: set noexpandtab tabstop=4: */