OpenCoverage

hash-triple.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/hash-triple.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* Hash functions for file-related triples: name, device, inode.-
2 Copyright (C) 2007, 2009-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation; either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* written by Jim Meyering */-
18-
19#include <config.h>-
20-
21#include "hash-triple.h"-
22-
23#include <stdlib.h>-
24#include <string.h>-
25-
26#include "hash-pjw.h"-
27#include "same.h"-
28#include "same-inode.h"-
29-
30#define STREQ(a, b) (strcmp (a, b) == 0)-
31-
32/* Hash an F_triple, and *do* consider the file name. */-
33size_t-
34triple_hash (void const *x, size_t table_size)-
35{-
36 struct F_triple const *p = x;-
37 size_t tmp = hash_pjw (p->name, table_size);-
38-
39 /* Ignoring the device number here should be fine. */-
40 return (tmp ^ p->st_ino) % table_size;
executed 18032 times by 6 tests: return (tmp ^ p->st_ino) % table_size;
Executed by:
  • cp
  • ginstall
  • ln
  • mv
  • readlink
  • realpath
18032
41}-
42-
43/* Hash an F_triple, without considering the file name. */-
44size_t-
45triple_hash_no_name (void const *x, size_t table_size)-
46{-
47 struct F_triple const *p = x;-
48-
49 /* Ignoring the device number here should be fine. */-
50 return p->st_ino % table_size;
executed 61 times by 1 test: return p->st_ino % table_size;
Executed by:
  • cp
61
51}-
52-
53/* Compare two F_triple structs. */-
54bool-
55triple_compare (void const *x, void const *y)-
56{-
57 struct F_triple const *a = x;-
58 struct F_triple const *b = y;-
59 return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false;
executed 5078 times by 3 tests: return (((*a).st_ino == (*b).st_ino && (*a).st_dev == (*b).st_dev) && same_name (a->name, b->name)) ? 1 : 0 ;
Executed by:
  • cp
  • ln
  • mv
5078
60}-
61-
62bool-
63triple_compare_ino_str (void const *x, void const *y)-
64{-
65 struct F_triple const *a = x;-
66 struct F_triple const *b = y;-
67 return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false;
executed 34 times by 1 test: return (((*a).st_ino == (*b).st_ino && (*a).st_dev == (*b).st_dev) && ( __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( a->name ) && __builtin_constant_p ( b->name ) && (__s1_len = __builtin_strlen ( a->name ), __s2_len = __builtin_str...igned char *) (const char *) ( b->name ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( b->name ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( a->name , b->name )))); }) == 0)) ? 1 : 0 ;
Executed by:
  • readlink
never executed: __result = (((const unsigned char *) (const char *) ( a->name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( b->name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-34
68}-
69-
70/* Free an F_triple. */-
71void-
72triple_free (void *x)-
73{-
74 struct F_triple *a = x;-
75 free (a->name);-
76 free (a);-
77}
executed 169 times by 4 tests: end of block
Executed by:
  • cp
  • ln
  • readlink
  • realpath
169
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2