Coverage Report

Created: 2025-11-09 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdbm/src/gdbmcount.c
Line
Count
Source
1
/* gdbmcount.c - get number of items in a gdbm file. */
2
3
/* This file is part of GDBM, the GNU data base manager.
4
   Copyright (C) 1993-2025 Free Software Foundation, Inc.
5
6
   GDBM is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3, or (at your option)
9
   any later version.
10
11
   GDBM is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with GDBM. If not, see <http://www.gnu.org/licenses/>.   */
18
19
/* Include system configuration before all else. */
20
#include "autoconf.h"
21
#include "gdbmdefs.h"
22
23
int
24
gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount)
25
2.81k
{
26
2.81k
  int nbuckets = GDBM_DIR_COUNT (dbf);
27
2.81k
  gdbm_count_t count = 0;
28
2.81k
  int i;
29
  
30
  /* Return immediately if the database needs recovery */  
31
2.81k
  GDBM_ASSERT_CONSISTENCY (dbf, -1);
32
  
33
4.75k
  for (i = 0; i < nbuckets; i = _gdbm_next_bucket_dir (dbf, i))
34
4.59k
    {
35
4.59k
      if (_gdbm_get_bucket (dbf, i))
36
1.90k
  return -1;
37
2.68k
      count += dbf->bucket->count;
38
2.68k
    }
39
156
  *pcount = count;
40
156
  return 0;
41
2.06k
}
42
43
int
44
gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount)
45
2.81k
{
46
2.81k
  int i;
47
2.81k
  size_t count = 0;
48
  
49
2.81k
  GDBM_ASSERT_CONSISTENCY (dbf, -1);
50
51
1.80k
  for (i = 0; i < GDBM_DIR_COUNT (dbf); i = _gdbm_next_bucket_dir (dbf, i))
52
1.65k
    {
53
1.65k
      ++count;
54
1.65k
    }
55
156
  *pcount = count;
56
156
  return 0;
57
2.81k
}