]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
* src/cp-hash.c (struct entry): Move dcl to this file from cp.h.
authorJim Meyering <jim@meyering.net>
Sun, 2 Feb 1997 22:21:03 +0000 (22:21 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 2 Feb 1997 22:21:03 +0000 (22:21 +0000)
(struct htab): Likewise.
No longer include cp.h.  Instead, include the things it used to include.

src/cp-hash.c

index b6aedc0a7175d2cc109d79fddcce0e5c61fc60a1..14fe478e3209406db446ab9c9121c3400cd84e0c 100644 (file)
 
 #include <config.h>
 #include <stdio.h>
-#include "cp.h"
+#include <sys/types.h>
+#include "system.h"
+#include "error.h"
+#include "cp-hash.h"
+
+struct entry
+{
+  ino_t ino;
+  dev_t dev;
+  char *node;                  /* Path name, or &new_file for new inodes.  */
+  struct entry *coll_link;     /* 0 = entry not occupied.  */
+};
+
+struct htab
+{
+  unsigned modulus;            /* Size of the `hash' pointer vector.  */
+  struct entry *entry_tab;     /* Pointer to dynamically growing vector.  */
+  unsigned entry_tab_size;     /* Size of current `entry_tab' allocation.  */
+  unsigned first_free_entry;   /* Index in `entry_tab'.  */
+  struct entry *hash[1];       /* Vector of pointers in `entry_tab'.  */
+};
+
+char *xmalloc ();
+char *xrealloc ();
 
 struct htab *htab;
 char new_file;
@@ -92,7 +115,47 @@ forget_all (void)
   for (i = htab->modulus; i > 0; i--)
     *p++ = NULL;
 }
-\f
+
+/* Insert path NODE, copied from inode number INO and device number DEV,
+   into the hash structure HTAB, if not already present.
+   Return NULL if inserted, otherwise non-NULL. */
+
+static char *
+hash_insert2 (struct htab *ht, ino_t ino, dev_t dev, const char *node)
+{
+  struct entry **hp, *ep2, *ep;
+  hp = &ht->hash[ino % ht->modulus];
+  ep2 = *hp;
+
+  /* Collision?  */
+
+  if (ep2 != NULL)
+    {
+      ep = ep2;
+
+      /* Search for an entry with the same data.  */
+
+      do
+       {
+         if (ep->ino == ino && ep->dev == dev)
+           return ep->node;    /* Found an entry with the same data.  */
+         ep = ep->coll_link;
+       }
+      while (ep != NULL);
+
+      /* Did not find it.  */
+
+    }
+
+  ep = *hp = &ht->entry_tab[ht->first_free_entry++];
+  ep->ino = ino;
+  ep->dev = dev;
+  ep->node = (char *) node;
+  ep->coll_link = ep2;         /* ep2 is NULL if not collision.  */
+
+  return NULL;
+}
+
 /* Insert path NODE, copied from inode number INO and device number DEV,
    into the hash structure in the global variable `htab', if an entry with
    the same inode and device was not found already.
@@ -160,43 +223,3 @@ hash_insert (ino_t ino, dev_t dev, const char *node)
 
   return hash_insert2 (htab_r, ino, dev, node);
 }
-
-/* Insert path NODE, copied from inode number INO and device number DEV,
-   into the hash structure HTAB, if not already present.
-   Return NULL if inserted, otherwise non-NULL. */
-
-char *
-hash_insert2 (struct htab *htab, ino_t ino, dev_t dev, const char *node)
-{
-  struct entry **hp, *ep2, *ep;
-  hp = &htab->hash[ino % htab->modulus];
-  ep2 = *hp;
-
-  /* Collision?  */
-
-  if (ep2 != NULL)
-    {
-      ep = ep2;
-
-      /* Search for an entry with the same data.  */
-
-      do
-       {
-         if (ep->ino == ino && ep->dev == dev)
-           return ep->node;    /* Found an entry with the same data.  */
-         ep = ep->coll_link;
-       }
-      while (ep != NULL);
-
-      /* Did not find it.  */
-
-    }
-
-  ep = *hp = &htab->entry_tab[htab->first_free_entry++];
-  ep->ino = ino;
-  ep->dev = dev;
-  ep->node = (char *) node;
-  ep->coll_link = ep2;         /* ep2 is NULL if not collision.  */
-
-  return NULL;
-}