Reintegrate header branch
[reactos.git] / reactos / lib / drivers / oskittcp / oskittcp / osenv.c
1 #include "oskittcp.h"
2
3 unsigned oskit_freebsd_cpl;
4
5 /* We have to store a reference count somewhere so we
6 * don't free a buffer being referenced in another mbuf.
7 * I just decided to add an extra char to the beginning of
8 * the buffer and store the reference count there. I doubt the ref count
9 * will ever even get close to 0xFF so we should be ok. Remember that
10 * only one thread can ever be inside oskit due to OSKLock so this should
11 * be safe.
12 */
13
14 void oskit_bufio_addref(void *buf)
15 {
16 unsigned char* fullbuf = ((unsigned char*)buf) - sizeof(char);
17
18 #if DBG
19 if (fullbuf[0] == 0xFF)
20 panic("oskit_bufio_addref: ref count overflow");
21 #endif
22
23 fullbuf[0]++;
24 }
25 void oskit_bufio_release(void *buf)
26 {
27 unsigned char* fullbuf = ((unsigned char*)buf) - sizeof(char);
28
29 if (--fullbuf[0] == 0)
30 free(fullbuf, 0);
31 }
32 void* oskit_bufio_create(int len)
33 {
34 unsigned char* fullbuf = malloc(len + sizeof(char), __FILE__, __LINE__);
35 if (fullbuf == NULL)
36 return NULL;
37
38 fullbuf[0] = 1;
39
40 return (void*)(fullbuf + sizeof(char));
41 }
42 void oskit_bufio_map(void *srcbuf, void**dstbuf, int off, int len)
43 {
44 *dstbuf = srcbuf;
45 }