data_structures
list_peek.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* list_peek.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/18 23:15:24 by unite #+# #+# */
10 /* Updated: 2020/09/07 22:01:07 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "list.h"
15 
16 void *list_peek(const t_list *alst, size_t index)
17 {
18  t_link *link;
19 
20  if (index >= alst->size)
21  ds_exit_set(EINVAL);
22  link = alst->head;
23  while (index-- > 0)
24  link = link->next;
25  return (link->content);
26 }
s_list::head
t_link * head
The first link.
Definition: list.h:56
s_list
Doubly-linked list of generic items.
Definition: list.h:54
s_list::size
size_t size
The number of items in the list.
Definition: list.h:58
list_peek
void * list_peek(const t_list *alst, size_t index)
Returns the item at the specified position in the list.
Definition: list_peek.c:16
list.h
ds_exit_set
void ds_exit_set(int err)
Set errno to the specified value, print the error message, and exit the process.
Definition: ds_exit_set.c:22