1219019Sgabor/*
2219019Sgabor * err.h : interface to routines for returning Berkeley DB errors
3219019Sgabor *
4219019Sgabor * ====================================================================
5219019Sgabor *    Licensed to the Apache Software Foundation (ASF) under one
6219019Sgabor *    or more contributor license agreements.  See the NOTICE file
7219019Sgabor *    distributed with this work for additional information
8219019Sgabor *    regarding copyright ownership.  The ASF licenses this file
9219019Sgabor *    to you under the Apache License, Version 2.0 (the
10 *    "License"); you may not use this file except in compliance
11 *    with the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 *    Unless required by applicable law or agreed to in writing,
16 *    software distributed under the License is distributed on an
17 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 *    KIND, either express or implied.  See the License for the
19 *    specific language governing permissions and limitations
20 *    under the License.
21 * ====================================================================
22 */
23
24
25
26#ifndef SVN_LIBSVN_FS_BDB_ERR_H
27#define SVN_LIBSVN_FS_BDB_ERR_H
28
29#include <apr_pools.h>
30
31#include "svn_error.h"
32#include "svn_fs.h"
33
34#include "env.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif /* __cplusplus */
39
40
41/* Return an svn_error_t object that reports a Berkeley DB error.
42   DB_ERR is the error value returned by the Berkeley DB routine.
43   Wrap and consume pending errors in BDB.  */
44svn_error_t *svn_fs_bdb__dberr(bdb_env_baton_t *bdb_baton, int db_err);
45
46
47/* Allocate an error object for a Berkeley DB error, with a formatted message.
48   Wrap and consume pending errors in BDB.
49
50   DB_ERR is the Berkeley DB error code.
51   FMT is a printf-style format string, describing how to format any
52      subsequent arguments.
53
54   The svn_error_t object returned has a message consisting of:
55   - the text specified by FMT and the subsequent arguments, and
56   - the Berkeley DB error message for the error code DB_ERR.
57
58   There is no separator between the two messages; if you want one,
59   you should include it in FMT.  */
60svn_error_t *svn_fs_bdb__dberrf(bdb_env_baton_t *bdb_baton, int db_err,
61                                const char *fmt, ...)
62       __attribute__((format(printf, 3, 4)));
63
64
65/* Clear errors associated with BDB. */
66void svn_fs_bdb__clear_err(bdb_env_t *bdb);
67
68
69/* Check the return status from the Berkeley DB operation.  If the
70   operation succeeded, return zero.  Otherwise, construct an
71   appropriate Subversion error object describing what went wrong.
72   - FS is the Subversion filesystem we're operating on.
73   - OPERATION is a gerund clause describing what we were trying to do.
74   - BDB_ERR is the return status from the Berkeley DB function.  */
75svn_error_t *svn_fs_bdb__wrap_db(svn_fs_t *fs,
76                                 const char *operation,
77                                 int db_err);
78
79
80/* A terse wrapper for svn_fs_bdb__wrap_db.  */
81#define BDB_WRAP(fs, op, err) (svn_fs_bdb__wrap_db((fs), (op), (err)))
82
83/* If EXPR returns a non-zero value, pass that value to
84   svn_fs_bdb__dberr and return that function's value.  This is like
85   SVN_ERR, but is used by functions that return a Subversion error
86   and call other functions that return a Berkeley DB error code. */
87#define SVN_BDB_ERR(bdb, expr)                           \
88  do {                                                   \
89    int db_err__temp = (expr);                           \
90    if (db_err__temp)                                    \
91      return svn_fs_bdb__dberr((bdb), db_err__temp);     \
92    svn_error_clear((bdb)->error_info->pending_errors);  \
93    (bdb)->error_info->pending_errors = NULL;            \
94  } while (0)
95
96
97/* If EXPR returns a non-zero value, return it.  This is like SVN_ERR,
98   but for functions that return a Berkeley DB error code.  */
99#define BDB_ERR(expr)                           \
100  do {                                          \
101    int db_err__temp = (expr);                  \
102    if (db_err__temp)                           \
103      return db_err__temp;                      \
104  } while (0)
105
106
107/* Verify that FS refers to an open database; return an appropriate
108   error if this is not the case.  */
109svn_error_t *svn_fs_bdb__check_fs(svn_fs_t *fs);
110
111#ifdef __cplusplus
112}
113#endif /* __cplusplus */
114
115#endif /* SVN_LIBSVN_FS_BDB_ERR_H */
116