r9965@lvps87-230-33-50: verhaegs | 2009-01-10 17:52:41 +0100
[AROS.git] / workbench / libs / codesetslib / src / utils.c
blob31fc4d4e1f936cb21029217f78406938246185f7
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-2007 by 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/
19 $Id$
21 ***************************************************************************/
23 #include "lib.h"
24 #include "debug.h"
26 /****************************************************************************/
28 #if !defined(HAVE_ALLOCVECPOOLED)
29 APTR
30 allocVecPooled(APTR pool,ULONG size)
32 ULONG *mem;
34 ENTER();
36 size += sizeof(ULONG);
37 if((mem = AllocPooled(pool, size)))
38 *mem++ = size;
40 RETURN(mem);
41 return mem;
43 #endif
45 /****************************************************************************/
47 #if !defined(HAVE_FREEVECPOOLED)
48 void
49 freeVecPooled(APTR pool,APTR mem)
51 ENTER();
53 FreePooled(pool,(LONG *)mem - 1,*((LONG *)mem - 1));
55 LEAVE();
57 #endif
59 /****************************************************************************/
61 APTR
62 reallocVecPooled(APTR pool, APTR mem, ULONG oldSize, ULONG newSize)
64 ULONG *newMem;
66 ENTER();
68 if((newMem = allocVecPooled(pool, newSize)) != NULL)
70 memcpy(newMem, mem, (oldSize < newSize) ? oldSize : newSize);
72 freeVecPooled(pool, mem);
75 RETURN(newMem);
76 return newMem;
79 /****************************************************************************/
81 APTR
82 allocArbitrateVecPooled(ULONG size)
84 ULONG *mem;
86 ENTER();
88 ObtainSemaphore(&CodesetsBase->poolSem);
89 mem = allocVecPooled(CodesetsBase->pool, size);
90 ReleaseSemaphore(&CodesetsBase->poolSem);
92 RETURN(mem);
93 return mem;
96 /****************************************************************************/
98 void
99 freeArbitrateVecPooled(APTR mem)
101 ENTER();
103 ObtainSemaphore(&CodesetsBase->poolSem);
104 freeVecPooled(CodesetsBase->pool, mem);
105 ReleaseSemaphore(&CodesetsBase->poolSem);
107 LEAVE();
110 /****************************************************************************/
112 APTR
113 reallocArbitrateVecPooled(APTR mem, ULONG oldSize, ULONG newSize)
115 ENTER();
117 ObtainSemaphore(&CodesetsBase->poolSem);
118 mem = reallocVecPooled(CodesetsBase->pool, mem, oldSize, newSize);
119 ReleaseSemaphore(&CodesetsBase->poolSem);
121 RETURN(mem);
122 return mem;
125 /****************************************************************************/