Mercurial > hg > octave-shane > gnulib-hg
annotate lib/hash-triple.c @ 17632:86af85d364e1 default tip
unistd: port readlink to Mac OS X 10.3.9
* lib/unistd.in.h (_GL_INCLUDING_UNISTD_H): New macro, to work
around self-include problem in Mac OS X 10.3.9 when combined with
readlink module. Problem reported by Klaus Zietler in
<http://bugs.gnu.org/16825>.
author | Paul Eggert <eggert@penguin.cs.ucla.edu> |
---|---|
date | Tue, 25 Feb 2014 11:16:27 -0800 |
parents | 344018b6e5d7 |
children |
rev | line source |
---|---|
9225 | 1 /* Hash functions for file-related triples: name, device, inode. |
17587 | 2 Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc. |
9225 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
9225 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
7 (at your option) any later version. |
9225 | 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 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9225 | 16 |
17 /* written by Jim Meyering */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include "hash-triple.h" | |
22 | |
23 #include <stdlib.h> | |
9233
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
24 #include <string.h> |
9225 | 25 |
26 #include "hash-pjw.h" | |
27 #include "same.h" | |
28 #include "same-inode.h" | |
29 | |
12772
2ea3e3fab7ee
define STREQ(a,b) consistently, removing useless parentheses
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
30 #define STREQ(a, b) (strcmp (a, b) == 0) |
9233
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
31 |
9225 | 32 /* Hash an F_triple, and *do* consider the file name. */ |
33 size_t | |
34 triple_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; | |
41 } | |
42 | |
43 /* Hash an F_triple, without considering the file name. */ | |
14612
6ef4f1f39105
Revert "use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE"
Jim Meyering <meyering@redhat.com>
parents:
14610
diff
changeset
|
44 size_t |
9225 | 45 triple_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; | |
51 } | |
52 | |
53 /* Compare two F_triple structs. */ | |
54 bool | |
55 triple_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; | |
60 } | |
61 | |
9233
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
62 bool |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
63 triple_compare_ino_str (void const *x, void const *y) |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
64 { |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
65 struct F_triple const *a = x; |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
66 struct F_triple const *b = y; |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
67 return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false; |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
68 } |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
69 |
9225 | 70 /* Free an F_triple. */ |
71 void | |
72 triple_free (void *x) | |
73 { | |
74 struct F_triple *a = x; | |
75 free (a->name); | |
76 free (a); | |
77 } |