TOR: fix compilation
[tomato.git] / release / src / router / mdadm / dlink.c
blobd7342815949813e671b9009f30686be513046b6d
2 /* doubly linked lists */
3 /* This is free software. No strings attached. No copyright claimed */
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #ifdef __dietlibc__
9 char *strncpy(char *dest, const char *src, size_t n) __THROW;
10 #endif
11 #include "dlink.h"
14 void *dl_head()
16 void *h;
17 h = dl_alloc(0);
18 dl_next(h) = h;
19 dl_prev(h) = h;
20 return h;
23 void dl_free(void *v)
25 struct __dl_head *vv = v;
26 free(vv-1);
29 void dl_init(void *v)
31 dl_next(v) = v;
32 dl_prev(v) = v;
35 void dl_insert(void *head, void *val)
37 dl_next(val) = dl_next(head);
38 dl_prev(val) = head;
39 dl_next(dl_prev(val)) = val;
40 dl_prev(dl_next(val)) = val;
43 void dl_add(void *head, void *val)
45 dl_prev(val) = dl_prev(head);
46 dl_next(val) = head;
47 dl_next(dl_prev(val)) = val;
48 dl_prev(dl_next(val)) = val;
51 void dl_del(void *val)
53 if (dl_prev(val) == 0 || dl_next(val) == 0)
54 return;
55 dl_prev(dl_next(val)) = dl_prev(val);
56 dl_next(dl_prev(val)) = dl_next(val);
57 dl_prev(val) = dl_next(val) = 0;
60 char *dl_strndup(char *s, int l)
62 char *n;
63 if (s == NULL)
64 return NULL;
65 n = dl_newv(char, l+1);
66 if (n == NULL)
67 return NULL;
68 else
70 strncpy(n, s, l);
71 n[l] = 0;
72 return n;
76 char *dl_strdup(char *s)
78 return dl_strndup(s, (int)strlen(s));