change PAD_ScanPads()s behaviour. the return value now contains a bitmask of the...
[libogc.git] / libdb / uIP / memb.c
blob5787a6db4ccdd4795ff2c9cd50925a790c09f957
1 #include <stdlib.h>
2 #include <string.h>
4 #include "uip.h"
5 #include "memb.h"
7 void memb_init(struct memb_blks *blk)
9 UIP_MEMSET(blk->mem,0,(MEM_ALIGN_SIZE(blk->size)+sizeof(u32))*blk->num);
12 void* memb_alloc(struct memb_blks *blk)
14 s32 i;
15 u32 *ptr;
17 ptr = (u32*)blk->mem;
18 for(i=0;i<blk->num;i++) {
19 if(*ptr==0) {
20 ++(*ptr);
21 return (void*)(ptr+1);
23 ptr = (u32*)(u8*)ptr+(MEM_ALIGN_SIZE(blk->size)+sizeof(u32));
25 return NULL;
28 u8 memb_free(struct memb_blks *blk,void *ptr)
30 s32 i;
31 u32 *ptr2,*ptr1;
33 ptr1 = ptr;
34 ptr2 = (u32*)blk->mem;
35 for(i=0;i<blk->num;i++) {
36 if(ptr2==(ptr1 - 1)) {
37 return --(*ptr2);
39 ptr2 = (u32*)(u8*)ptr2+(MEM_ALIGN_SIZE(blk->size)+sizeof(u32));
41 return -1;
44 u8 memb_ref(struct memb_blks *blk,void *ptr)
46 u32 *pref = ptr-sizeof(u32);
47 return ++(*pref);