MCPcopy Create free account
hub / github.com/coreutils/coreutils / remember_copied

Function remember_copied

src/cp-hash.c:114–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112 Return NULL if inserted, otherwise a non-null pointer. */
113
114extern char *
115remember_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. */
146extern void

Callers 1

copy_internalFunction · 0.85

Calls 2

xalloc_dieFunction · 0.85
src_to_dest_freeFunction · 0.85

Tested by

no test coverage detected