Prevent movingMake it clear that this is a current outside thecircular linked list
In your code for moving the current pointer forward or backwardsTo distinguish it from a regular linked list, I see this:
for (ptrdiff_t i = 0; i < n; i++) {
list->current = list->current->next;
if (list->current == list->head)
status++;
}
This loop will happily try to go pastmake sure the endnames of the list if n is too large, resulting in a segmentation fault. The check for list->current == list->head is very weird,structs and functions make it will never trigger (if current was list->head,clear that it will have moved past this before this if-statement is triggered), and it doesn't break out of the loopa circular linked list. The code should probably be:
for (ptrdiff_t i = 0; i < n; i++) {
if (list->current->next)
list->current = list->current->next;
else
return -1;
}
This prevents list->current from becoming NULL, and returns an errorIt's also best if it would have otherwise moved past the end of the list. Note thatfilenames themselves reflect this code still doesn't handle the case when trying to move in an empty list.