summaryrefslogtreecommitdiff
path: root/gl/lib/file-set.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-08-23 10:47:16 +0200
committerJim Meyering <jim@meyering.net>2007-08-23 13:59:40 +0200
commit22ed81c410c197003782ba379cb3148306b0cd8a (patch)
tree3faddb492038c4eed405090a032c7312d072aa7e /gl/lib/file-set.c
parent173524ed7d0bb5f458251b796f23a2dfc49a4b24 (diff)
downloadcoreutils-22ed81c410c197003782ba379cb3148306b0cd8a.tar.xz
Move functions from copy.c into new modules, since ln needs them, too.
* bootstrap.conf (gnulib_modules): Add file-set. * gl/lib/file-set.c (record_file, seen_file): Functions from copy.c. * gl/lib/file-set.h: Add prototypes. * gl/lib/hash-triple.c (triple_hash, triple_hash_no_name): (triple_compare, triple_free): Functions from copy.c. * gl/lib/hash-triple.h (struct F_triple): Define. From copy.c. Add prototypes. * gl/modules/file-set: New module. * gl/modules/hash-triple: New module. * src/Makefile.am (copy_sources): New variable. (ginstall_SOURCES, cp_SOURCES, mv_SOURCES): Use it. * src/copy.c: Include hash-triple.h. No longer include hash-pjw.h. (copy_internal): Don't pass a NULL third argument to record_file, since that function no longer accepts that. (record_file): Move this function to file-set.c. Along the way, remove the code to allow a NULL stat-buffer pointer. Adjust sole caller. (seen_file): Move this function to file-set.c. (struct F_triple): Move declaration to hash-triple.h. (triple_compare, triple_free, triple_hash, triple_hash_no_name): Move these functions to hash-triple.c. Signed-off-by: Jim Meyering <jim@meyering.net>
Diffstat (limited to 'gl/lib/file-set.c')
-rw-r--r--gl/lib/file-set.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/gl/lib/file-set.c b/gl/lib/file-set.c
new file mode 100644
index 000000000..ad03f90ce
--- /dev/null
+++ b/gl/lib/file-set.c
@@ -0,0 +1,56 @@
+#include <config.h>
+#include "file-set.h"
+
+#include "hash-triple.h"
+#include "xalloc.h"
+
+/* Record destination file, FILE, and dev/ino from *STATS,
+ in the hash table, HT. If HT is NULL, return immediately.
+ If memory allocation fails, exit immediately. */
+void
+record_file (Hash_table *ht, char const *file, struct stat const *stats)
+{
+ struct F_triple *ent;
+
+ if (ht == NULL)
+ return;
+
+ ent = xmalloc (sizeof *ent);
+ ent->name = xstrdup (file);
+ ent->st_ino = stats->st_ino;
+ ent->st_dev = stats->st_dev;
+
+ {
+ struct F_triple *ent_from_table = hash_insert (ht, ent);
+ if (ent_from_table == NULL)
+ {
+ /* Insertion failed due to lack of memory. */
+ xalloc_die ();
+ }
+
+ if (ent_from_table != ent)
+ {
+ /* There was alread a matching entry in the table, so ENT was
+ not inserted. Free it. */
+ triple_free (ent);
+ }
+ }
+}
+
+/* Return true if there is an entry in hash table, HT,
+ for the file described by FILE and STATS. */
+bool
+seen_file (Hash_table const *ht, char const *file,
+ struct stat const *stats)
+{
+ struct F_triple new_ent;
+
+ if (ht == NULL)
+ return false;
+
+ new_ent.name = (char *) file;
+ new_ent.st_ino = stats->st_ino;
+ new_ent.st_dev = stats->st_dev;
+
+ return !!hash_lookup (ht, &new_ent);
+}