-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_ldcdat.c
executable file
·41 lines (38 loc) · 1.4 KB
/
ft_ldcdat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ldcdat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tseguier <tseguier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2013/12/05 23:50:16 by tseguier #+# #+# */
/* Updated: 2014/03/27 18:45:18 by jcoignet ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include "libft.h"
size_t ft_ldcdat(t_ldcd ldcd, const void **at, unsigned int i)
{
t_ldcd_cell iter;
unsigned int j;
if (!ldcd || !at || i >= ldcd->size)
{
if (at)
*at = NULL;
return (0);
}
iter = (i < (unsigned int)ldcd->size / 2) ? ldcd->head : ldcd->tail;
j = (i < (unsigned int)ldcd->size / 2) ? 0 : (ldcd->size - 1);
if (iter == ldcd->head)
{
while (j++ < i)
iter = iter->next;
}
else
{
while (j-- > i)
iter = iter->prev;
}
*at = iter->content;
return (iter->content_size);
}