Advertisement
Guest User

Untitled

a guest
Oct 26th, 2010
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1.  
  2. // cpfs interface enter/exit wrappers
  3.  
  4. #define CPFS_ENTER(fmt, ...) \
  5.     do { \
  6.         log_info(fmt, ##__VA_ARGS__); \
  7.         util_cpfs_enter(cpfs_); \
  8.         cpfs_ = NULL; \
  9.     } while (false)
  10.  
  11. #define _CPFS_RETURN(commit, retval) do { \
  12.         util_cpfs_exit(commit, __func__); \
  13.         return retval; \
  14.     } while (false)
  15.  
  16. // these wrappers could be done using type-generic macros
  17. // supported by GCC and C1x
  18.  
  19. #define CPFS_RETURN_BOOL(retval) do { \
  20.         static_assert(std::is_same<decltype(retval), bool>::value, "retval must be bool"); \
  21.         bool _rv_ = (retval); \
  22.         _CPFS_RETURN(_rv_, _rv_); \
  23.     } while (false)
  24.  
  25. #define CPFS_RETURN_FD(retval) do { \
  26.         static_assert(std::is_same<decltype(retval), int>::value, "retval must be int"); \
  27.         int _rv_ = (retval); \
  28.         if (_rv_ == -1) _CPFS_RETURN(false, _rv_); \
  29.         else { assert(fd_valid(_rv_)); _CPFS_RETURN(true, _rv_); } \
  30.     } while (false)
  31.  
  32. #define CPFS_RETURN_SIZE(retval, count) do { \
  33.         static_assert(std::is_same<decltype(retval), CpfsSizeRet>::value, "retval must be CpfsSizeRet"); \
  34.         CpfsSizeRet _rv_ = (retval); \
  35.         decltype(_rv_) _cnt_ VARATTR_UNUSED = (count); \
  36.         if (_rv_ == -1) _CPFS_RETURN(false, _rv_); \
  37.         else { assert(_rv_ <= _cnt_); _CPFS_RETURN(true, _rv_); } \
  38.     } while (false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement