Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/ino-map.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | struct ino_map_ent | - | ||||||
8 | { | - | ||||||
9 | ino_t ino; | - | ||||||
10 | size_t mapped_ino; | - | ||||||
11 | }; | - | ||||||
12 | - | |||||||
13 | - | |||||||
14 | struct ino_map | - | ||||||
15 | { | - | ||||||
16 | - | |||||||
17 | - | |||||||
18 | struct hash_table *map; | - | ||||||
19 | - | |||||||
20 | - | |||||||
21 | size_t next_mapped_ino; | - | ||||||
22 | - | |||||||
23 | - | |||||||
24 | - | |||||||
25 | struct ino_map_ent *probe; | - | ||||||
26 | }; | - | ||||||
27 | - | |||||||
28 | - | |||||||
29 | static size_t | - | ||||||
30 | ino_hash (void const *x, size_t table_size) | - | ||||||
31 | { | - | ||||||
32 | struct ino_map_ent const *p = x; | - | ||||||
33 | ino_t ino = p->ino; | - | ||||||
34 | - | |||||||
35 | - | |||||||
36 | - | |||||||
37 | - | |||||||
38 | size_t h = ino; | - | ||||||
39 | unsigned int i; | - | ||||||
40 | unsigned int n_words = sizeof ino / sizeof h + (sizeof ino % sizeof h != 0); | - | ||||||
41 | for (i = 1; i < n_words
| 0 | ||||||
42 | h ^= ino >> 8 * sizeof h * i; never executed: h ^= ino >> 8 * sizeof h * i; | 0 | ||||||
43 | - | |||||||
44 | return never executed: h % table_size;return h % table_size; never executed: return h % table_size; | 0 | ||||||
45 | } | - | ||||||
46 | - | |||||||
47 | - | |||||||
48 | static | - | ||||||
49 | _Bool | - | ||||||
50 | - | |||||||
51 | ino_compare (void const *x, void const *y) | - | ||||||
52 | { | - | ||||||
53 | struct ino_map_ent const *a = x; | - | ||||||
54 | struct ino_map_ent const *b = y; | - | ||||||
55 | return never executed: a->ino == b->ino;return a->ino == b->ino; never executed: return a->ino == b->ino; | 0 | ||||||
56 | } | - | ||||||
57 | - | |||||||
58 | - | |||||||
59 | - | |||||||
60 | struct ino_map * | - | ||||||
61 | ino_map_alloc (size_t next_mapped_ino) | - | ||||||
62 | { | - | ||||||
63 | struct ino_map *im = malloc (sizeof *im); | - | ||||||
64 | - | |||||||
65 | if (im
| 0 | ||||||
66 | { | - | ||||||
67 | enum { INITIAL_INO_MAP_TABLE_SIZE = 1021 }; | - | ||||||
68 | im->map = hash_initialize (INITIAL_INO_MAP_TABLE_SIZE, | - | ||||||
69 | ((void *)0) | - | ||||||
70 | , | - | ||||||
71 | ino_hash, ino_compare, free); | - | ||||||
72 | if (! im->map
| 0 | ||||||
73 | { | - | ||||||
74 | free (im); | - | ||||||
75 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||
76 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||
77 | ; never executed: return ((void *)0) ; | 0 | ||||||
78 | } | - | ||||||
79 | im->next_mapped_ino = next_mapped_ino; | - | ||||||
80 | im->probe = | - | ||||||
81 | ((void *)0) | - | ||||||
82 | ; | - | ||||||
83 | } never executed: end of block | 0 | ||||||
84 | - | |||||||
85 | return never executed: im;return im; never executed: return im; | 0 | ||||||
86 | } | - | ||||||
87 | - | |||||||
88 | - | |||||||
89 | void | - | ||||||
90 | ino_map_free (struct ino_map *map) | - | ||||||
91 | { | - | ||||||
92 | hash_free (map->map); | - | ||||||
93 | free (map->probe); | - | ||||||
94 | free (map); | - | ||||||
95 | } never executed: end of block | 0 | ||||||
96 | - | |||||||
97 | - | |||||||
98 | - | |||||||
99 | - | |||||||
100 | - | |||||||
101 | - | |||||||
102 | size_t | - | ||||||
103 | ino_map_insert (struct ino_map *im, ino_t ino) | - | ||||||
104 | { | - | ||||||
105 | struct ino_map_ent *ent; | - | ||||||
106 | - | |||||||
107 | - | |||||||
108 | struct ino_map_ent *probe = im->probe; | - | ||||||
109 | if (probe
| 0 | ||||||
110 | { | - | ||||||
111 | - | |||||||
112 | if (probe->ino == ino
| 0 | ||||||
113 | return never executed: probe->mapped_ino;return probe->mapped_ino; never executed: return probe->mapped_ino; | 0 | ||||||
114 | } never executed: end of block | 0 | ||||||
115 | else | - | ||||||
116 | { | - | ||||||
117 | im->probe = probe = malloc (sizeof *probe); | - | ||||||
118 | if (! probe
| 0 | ||||||
119 | return never executed: ((size_t) -1);return ((size_t) -1); never executed: return ((size_t) -1); | 0 | ||||||
120 | } never executed: end of block | 0 | ||||||
121 | - | |||||||
122 | probe->ino = ino; | - | ||||||
123 | ent = hash_insert (im->map, probe); | - | ||||||
124 | if (! ent
| 0 | ||||||
125 | return never executed: ((size_t) -1);return ((size_t) -1); never executed: return ((size_t) -1); | 0 | ||||||
126 | - | |||||||
127 | if (ent != probe
| 0 | ||||||
128 | { | - | ||||||
129 | - | |||||||
130 | probe->mapped_ino = ent->mapped_ino; | - | ||||||
131 | } never executed: end of block | 0 | ||||||
132 | else | - | ||||||
133 | { | - | ||||||
134 | - | |||||||
135 | - | |||||||
136 | - | |||||||
137 | - | |||||||
138 | _Static_assert (((size_t) -1) + 1 == 0, "verify (" "INO_MAP_INSERT_FAILURE + 1 == 0" ")"); | - | ||||||
139 | - | |||||||
140 | - | |||||||
141 | im->probe = | - | ||||||
142 | ((void *)0) | - | ||||||
143 | ; | - | ||||||
144 | - | |||||||
145 | - | |||||||
146 | probe->mapped_ino = im->next_mapped_ino++; | - | ||||||
147 | } never executed: end of block | 0 | ||||||
148 | - | |||||||
149 | return never executed: probe->mapped_ino;return probe->mapped_ino; never executed: return probe->mapped_ino; | 0 | ||||||
150 | } | - | ||||||
Switch to Source code | Preprocessed file |