From 65227dd4d47e6aa99a3087f119686084bcc78b8e Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 18 Jun 2020 13:35:35 -0400 Subject: [PATCH] cephfs: add a getErrorIfNegative helper func Works like the ones already in the other packages. Signed-off-by: John Mulligan --- cephfs/errors.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cephfs/errors.go b/cephfs/errors.go index 52d5aa7..9edd55a 100644 --- a/cephfs/errors.go +++ b/cephfs/errors.go @@ -35,6 +35,16 @@ func getError(e C.int) error { return cephFSError(e) } +// getErrorIfNegative converts a ceph return code to error if negative. +// This is useful for functions that return a usable positive value on +// success but a negative error number on error. +func getErrorIfNegative(ret C.int) error { + if ret >= 0 { + return nil + } + return getError(ret) +} + // Public go errors: var (