Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/file-set.c @ 14079:97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Run the new "make update-copyright" rule.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sat, 01 Jan 2011 20:17:23 +0100 |
parents | c2cbabec01dd |
children | 8250f2777afc |
rev | line source |
---|---|
9226 | 1 /* Specialized functions to manipulate a set of files. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
2 Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc. |
9226 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9226
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
9226 | 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:
9226
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:
9226
diff
changeset
|
7 (at your option) any later version. |
9226 | 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:
9226
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9226 | 16 |
17 /* written by Jim Meyering */ | |
18 | |
19 #include <config.h> | |
20 #include "file-set.h" | |
21 | |
22 #include "hash-triple.h" | |
23 #include "xalloc.h" | |
24 | |
25 /* Record file, FILE, and dev/ino from *STATS, in the hash table, HT. | |
26 If HT is NULL, return immediately. | |
27 If memory allocation fails, exit immediately. */ | |
28 void | |
29 record_file (Hash_table *ht, char const *file, struct stat const *stats) | |
30 { | |
31 struct F_triple *ent; | |
32 | |
33 if (ht == NULL) | |
34 return; | |
35 | |
36 ent = xmalloc (sizeof *ent); | |
37 ent->name = xstrdup (file); | |
38 ent->st_ino = stats->st_ino; | |
39 ent->st_dev = stats->st_dev; | |
40 | |
41 { | |
42 struct F_triple *ent_from_table = hash_insert (ht, ent); | |
43 if (ent_from_table == NULL) | |
44 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
45 /* Insertion failed due to lack of memory. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
46 xalloc_die (); |
9226 | 47 } |
48 | |
49 if (ent_from_table != ent) | |
50 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
51 /* There was alread a matching entry in the table, so ENT was |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
52 not inserted. Free it. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
53 triple_free (ent); |
9226 | 54 } |
55 } | |
56 } | |
57 | |
58 /* Return true if there is an entry in hash table, HT, | |
59 for the file described by FILE and STATS. */ | |
60 bool | |
61 seen_file (Hash_table const *ht, char const *file, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
62 struct stat const *stats) |
9226 | 63 { |
64 struct F_triple new_ent; | |
65 | |
66 if (ht == NULL) | |
67 return false; | |
68 | |
69 new_ent.name = (char *) file; | |
70 new_ent.st_ino = stats->st_ino; | |
71 new_ent.st_dev = stats->st_dev; | |
72 | |
73 return !!hash_lookup (ht, &new_ent); | |
74 } |