/* A shallow copy is a copy of a structure, but not the copy of the contents. All data pointers ('path' in our case) of a list and its shallow copy will point to the same memory. */
dep_list* dl_shallow_copy(const dep_list *dl)
/* A shallow copy is a copy of a structure, but not the copy of the contents. All data pointers ('path' in our case) of a list and its shallow copy will point to the same memory. */
dep_list* dl_shallow_copy(const dep_list *dl)
{
    if (dl == NULL) {
        return NULL;
    }
    dep_list *head = calloc (1, sizeof (dep_list));
    if (head == NULL) {
        perror_msg ("Failed to allocate head during shallow copy");
        return NULL;
    }
    dep_list *cp = head;
    const dep_list *it = dl;
    while (it != NULL) {
        cp->path = it->path;
        cp->inode = it->inode;
        if (it->next) {
            cp->next = calloc (1, sizeof (dep_list));
            if (cp->next == NULL) {
                perror_msg ("Failed to allocate a new element during shallow copy");
                dl_shallow_free (head);
                return NULL;
            }
            cp = cp->next;
        }
        it = it->next;
    }
    return head;
}