]> git.cworth.org Git - tar/blob - gnu/file-set.c
Imported Upstream version 1.23
[tar] / gnu / file-set.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Specialized functions to manipulate a set of files.
4    Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc.
5
6    This program 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 of the License, or
9    (at your option) any later version.
10
11    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 /* written by Jim Meyering */
20
21 #include <config.h>
22 #include "file-set.h"
23
24 #include "hash-triple.h"
25 #include "xalloc.h"
26
27 /* Record file, FILE, and dev/ino from *STATS, in the hash table, HT.
28    If HT is NULL, return immediately.
29    If memory allocation fails, exit immediately.  */
30 void
31 record_file (Hash_table *ht, char const *file, struct stat const *stats)
32 {
33   struct F_triple *ent;
34
35   if (ht == NULL)
36     return;
37
38   ent = xmalloc (sizeof *ent);
39   ent->name = xstrdup (file);
40   ent->st_ino = stats->st_ino;
41   ent->st_dev = stats->st_dev;
42
43   {
44     struct F_triple *ent_from_table = hash_insert (ht, ent);
45     if (ent_from_table == NULL)
46       {
47         /* Insertion failed due to lack of memory.  */
48         xalloc_die ();
49       }
50
51     if (ent_from_table != ent)
52       {
53         /* There was alread a matching entry in the table, so ENT was
54            not inserted.  Free it.  */
55         triple_free (ent);
56       }
57   }
58 }
59
60 /* Return true if there is an entry in hash table, HT,
61    for the file described by FILE and STATS.  */
62 bool
63 seen_file (Hash_table const *ht, char const *file,
64            struct stat const *stats)
65 {
66   struct F_triple new_ent;
67
68   if (ht == NULL)
69     return false;
70
71   new_ent.name = (char *) file;
72   new_ent.st_ino = stats->st_ino;
73   new_ent.st_dev = stats->st_dev;
74
75   return !!hash_lookup (ht, &new_ent);
76 }