github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/status.h (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  #pragma once
    12  
    13  #include "db.h"
    14  #include "fmt.h"
    15  
    16  namespace cockroach {
    17  
    18  const DBStatus kSuccess = {NULL, 0};
    19  
    20  // ToDBStatus converts a rocksdb Status to a DBStatus.
    21  inline DBStatus ToDBStatus(const rocksdb::Status& status) {
    22    if (status.ok()) {
    23      return kSuccess;
    24    }
    25    return ToDBString(status.ToString());
    26  }
    27  
    28  // FmtStatus formats the given arguments printf-style into a DBStatus.
    29  __attribute__((__format__(GOOGLE_PRINTF_FORMAT, 1, 2))) inline DBStatus
    30  FmtStatus(const char* fmt_str, ...) {
    31    va_list ap;
    32    va_start(ap, fmt_str);
    33    std::string str;
    34    fmt::StringAppendV(&str, fmt_str, ap);
    35    va_end(ap);
    36    return ToDBString(str);
    37  }
    38  
    39  }  // namespace cockroach