1 /***************************************************************************
3 codesets.library - Amiga shared library for handling different codesets
4 Copyright (C) 2001-2005 by Alfonso [alfie] Ranieri <alforan@tin.it>.
5 Copyright (C) 2005-2014 codesets.library Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 codesets.library project: http://sourceforge.net/projects/codesetslib/
21 ***************************************************************************/
26 /****************************************************************************/
28 #if !defined(HAVE_ALLOCVECPOOLED)
29 APTR
allocVecPooled(APTR pool
,ULONG size
)
35 size
+= sizeof(ULONG
);
36 if((mem
= AllocPooled(pool
, size
)))
44 /****************************************************************************/
46 #if !defined(HAVE_FREEVECPOOLED)
47 void freeVecPooled(APTR pool
,APTR mem
)
51 FreePooled(pool
,(LONG
*)mem
- 1,*((LONG
*)mem
- 1));
57 /****************************************************************************/
59 APTR
reallocVecPooled(APTR pool
, APTR mem
, ULONG oldSize
, ULONG newSize
)
65 if((newMem
= allocVecPooled(pool
, newSize
)) != NULL
)
67 memcpy(newMem
, mem
, (oldSize
< newSize
) ? oldSize
: newSize
);
69 freeVecPooled(pool
, mem
);
76 /****************************************************************************/
78 APTR
allocArbitrateVecPooled(ULONG size
)
84 ObtainSemaphore(&CodesetsBase
->poolSem
);
85 mem
= allocVecPooled(CodesetsBase
->pool
, size
);
86 ReleaseSemaphore(&CodesetsBase
->poolSem
);
92 /****************************************************************************/
94 void freeArbitrateVecPooled(APTR mem
)
98 ObtainSemaphore(&CodesetsBase
->poolSem
);
99 freeVecPooled(CodesetsBase
->pool
, mem
);
100 ReleaseSemaphore(&CodesetsBase
->poolSem
);
105 /****************************************************************************/
107 APTR
reallocArbitrateVecPooled(APTR mem
, ULONG oldSize
, ULONG newSize
)
111 ObtainSemaphore(&CodesetsBase
->poolSem
);
112 mem
= reallocVecPooled(CodesetsBase
->pool
, mem
, oldSize
, newSize
);
113 ReleaseSemaphore(&CodesetsBase
->poolSem
);
119 /****************************************************************************/
121 ULONG
utf16_strlen(UTF16
*ptr
)
125 for (l
=0; ptr
[l
]; l
++);
129 /****************************************************************************/
131 ULONG
utf32_strlen(UTF32
*ptr
)
135 for (l
=0; ptr
[l
]; l
++);
139 /****************************************************************************/
142 // get the head element of a list
143 #if !defined(HAVE_GETHEAD)
144 struct Node
*GetHead(struct List
*list
)
146 struct Node
*result
= NULL
;
148 if(list
!= NULL
&& IsListEmpty(list
) == FALSE
)
149 result
= list
->lh_Head
;
155 /****************************************************************************/
158 // get a node's predecessor
159 #if !defined(HAVE_GETPRED)
160 struct Node
*GetPred(struct Node
*node
)
162 struct Node
*result
= NULL
;
164 if(node
!= NULL
&& node
->ln_Pred
!= NULL
&& node
->ln_Pred
->ln_Pred
!= NULL
)
165 result
= node
->ln_Pred
;
171 /****************************************************************************/
174 // get a node's sucessor
175 #if !defined(HAVE_GETSUCC)
176 struct Node
*GetSucc(struct Node
*node
)
178 struct Node
*result
= NULL
;
180 if(node
!= NULL
&& node
->ln_Succ
!= NULL
&& node
->ln_Succ
->ln_Succ
!= NULL
)
181 result
= node
->ln_Succ
;
187 /****************************************************************************/
190 // get the tail element of a list
191 #if !defined(HAVE_GETTAIL)
192 struct Node
*GetTail(struct List
*list
)
194 struct Node
*result
= NULL
;
196 if(list
!= NULL
&& IsListEmpty(list
) == FALSE
)
197 result
= list
->lh_TailPred
;