| 112 | Return NULL if inserted, otherwise a non-null pointer. */ |
| 113 | |
| 114 | extern char * |
| 115 | remember_copied (char const *name, ino_t ino, dev_t dev) |
| 116 | { |
| 117 | struct Src_to_dest *ent; |
| 118 | struct Src_to_dest *ent_from_table; |
| 119 | |
| 120 | ent = xmalloc (sizeof *ent); |
| 121 | ent->name = xstrdup (name); |
| 122 | ent->st_ino = ino; |
| 123 | ent->st_dev = dev; |
| 124 | |
| 125 | ent_from_table = hash_insert (src_to_dest, ent); |
| 126 | if (ent_from_table == NULL) |
| 127 | { |
| 128 | /* Insertion failed due to lack of memory. */ |
| 129 | xalloc_die (); |
| 130 | } |
| 131 | |
| 132 | /* Determine whether there was already an entry in the table |
| 133 | with a matching key. If so, free ENT (it wasn't inserted) and |
| 134 | return the 'name' from the table entry. */ |
| 135 | if (ent_from_table != ent) |
| 136 | { |
| 137 | src_to_dest_free (ent); |
| 138 | return (char *) ent_from_table->name; |
| 139 | } |
| 140 | |
| 141 | /* New key; insertion succeeded. */ |
| 142 | return NULL; |
| 143 | } |
| 144 | |
| 145 | /* Initialize the hash table. */ |
| 146 | extern void |
no test coverage detected