Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / libraries / popupmenu / pmmem.c
bloba45f11fa45a84987ad22416c645adc33b8bd8464
1 //
2 // pmmem.h
3 //
4 // $Date$
5 // $Revision$
6 //
8 #include "pmpriv.h"
9 #include "pmmem.h"
11 APTR PM_AllocVecPooled(size_t size)
13 APTR ptr;
15 if (MemPool)
17 ObtainSemaphore(&MemPoolSemaphore);
18 ptr = AllocPooled(MemPool, size + sizeof(size_t));
19 ReleaseSemaphore(&MemPoolSemaphore);
20 if (ptr)
22 size_t *sptr = (size_t *) ptr;
24 sptr[0] = size;
26 d1(kprintf(__FILE__ "/%s/%ld: MemPool=%08lx Size=%lu mem=%08lx\n",
27 __FUNC__, __LINE__, MemPool, size, &sptr[1]));
28 return (APTR)(&sptr[1]);
32 d1(kprintf(__FILE__ "/%s/%ld: MemPool=%08lx Size=%lu\n", __FUNC__, __LINE__, MemPool, size));
34 return NULL;
37 void PM_FreeVecPooled(APTR mem)
39 d1(kprintf(__FUNC__ "/%ld: MemPool=%08lx mem=%08lx\n", __LINE__, MemPool, mem));
40 if (MemPool && mem)
42 size_t size;
43 size_t *sptr = (size_t *) mem;
45 mem = &sptr[-1];
46 size = sptr[-1];
48 d1(kprintf(__FILE__ "/%s/%ld: MemPool=%08lx size=%lu mem=%08lx\n",
49 __FUNC__, __LINE__, MemPool, size, &sptr[1]));
51 ObtainSemaphore(&MemPoolSemaphore);
52 FreePooled(MemPool, mem, size + sizeof(size_t));
53 ReleaseSemaphore(&MemPoolSemaphore);
57 ULONG PM_String_Length(STRPTR s)
59 ULONG r=(ULONG)s;
61 while (*s++);
63 return ((ULONG)s)-r;
66 STRPTR PM_String_Copy(STRPTR Source, STRPTR Dest, LONG Len)
68 if (Len==-1)
70 while (*Source)
71 *Dest++=*Source++;
72 *Dest++=0;
73 return Dest;
75 else
77 LONG ctr=0;
79 while (ctr<Len)
81 Dest[ctr]=Source[ctr];
82 ctr++;
84 return &Dest[ctr];
88 ULONG PM_String_Compare(STRPTR str1, STRPTR str2)
90 ULONG i, j=0;
92 if (!str1 || !str2)
93 return 0;
94 for(i=0;;i++)
96 j+=str1[i];
97 j-=str2[i];
98 if (!str1[i] || !str2[i] || j)
99 return j;
103 void PM_StrCat(STRPTR str1, STRPTR str2)
105 while (*str1)
106 str1++;
107 while (*str2)
108 *str1++=*str2++;
109 *str1=0;