1 /* $Id: support.c 10.11 1998/09/27 11:26:37 Michiel Exp Michiel $ */
3 * Revision 10.11 1998/09/27 11:26:37 Michiel
4 * ErrorMsg extra param.
6 * Revision 10.10 1996/01/30 12:51:14 Michiel
7 * --- working tree overlap ---
8 * Free memory functions check for NULL pointers
10 * Revision 10.9 1995/10/04 14:03:17 Michiel
11 * amigalib memorypools -> support 2.0 too
13 * Revision 10.8 1995/09/01 11:17:41 Michiel
14 * ErrorMsg adaption (see disk.c and volume.c)
16 * Revision 10.7 1995/08/04 11:50:37 Michiel
17 * From default allocate-retry to default not-retry-but-fail
19 * Revision 10.6 1995/07/21 06:57:10 Michiel
20 * fixed bug in AllocBufmemR (double size registration)
22 * Revision 10.5 1995/07/11 17:29:31 Michiel
23 * ErrorMsg () calls use messages.c variables now.
25 * Revision 10.4 1995/06/16 10:02:17 Michiel
26 * added pool for buffer memory
28 * Revision 10.3 1995/06/15 18:56:21 Michiel
32 * Revision 10.2 1995/01/29 07:34:57 Michiel
35 * Revision 10.1 1994/10/24 11:16:28 Michiel
39 static void OutOfMemory (globaldata
*g
);
42 * Allocate from main pool (type MEMF_CLEAR)
45 void *AllocPooledVec (ULONG size
, globaldata
*g
)
49 buffer
= LibAllocPooled (g
->mainPool
, size
+sizeof(ULONG
));
56 void FreePooledVec (void *mem
, globaldata
*g
)
59 LibFreePooled (g
->mainPool
, (ULONG
*)mem
- 1, *((ULONG
*)mem
- 1) + sizeof(ULONG
));
65 void *AllocPooledBuf (ULONG size
, globaldata
*g
)
69 buffer
= LibAllocPooled (g
->bufferPool
, size
+sizeof(ULONG
));
73 if (((IPTR
)buffer
) & ~g
->dosenvec
->de_Mask
)
74 ErrorMsg (AFS_WARNING_MEMORY_MASK
, NULL
, g
);
79 void FreePooledBuf (void *mem
, globaldata
*g
)
82 LibFreePooled (g
->bufferPool
, (ULONG
*)mem
- 1, *((ULONG
*)mem
- 1) + sizeof(ULONG
));
87 * retrying variants of 'globaldata' allocation functions
89 void *AllocMemPR (ULONG size
, globaldata
*g
)
93 while (!(buffer
= AllocMemP (size
, g
)))
99 void *AllocBufmemR (ULONG size
, globaldata
*g
)
103 while (!(buffer
= AllocBufmem (size
, g
)))
112 VOID
*AllocMemR (ULONG size
, ULONG flags
, globaldata
*g
)
116 while (!(buffer
=AllocVec (size
, flags
)))
119 NormalErrorMsg (AFS_ERROR_PLEASE_FREE_MEM
, NULL
, 1); // I MUST have memory!
125 static void OutOfMemory (globaldata
*g
)
127 FreeUnusedResources (g
->currentvolume
, g
);
128 NormalErrorMsg (AFS_ERROR_PLEASE_FREE_MEM
, NULL
, 1); // I MUST have memory!
132 /* SUPPORTFUNCTION dstricmp
133 ** TRUE: dstring == cstring
134 ** FALSE: cstring <> cstring
136 BOOL
dstricmp (DSTR dstring
, STRPTR cstring
)
139 UBYTE temp
[PATHSIZE
];
141 ctodstr (cstring
, temp
);
143 result
= intlcmp (temp
, dstring
);
148 ** compare two dstrings
150 BOOL
ddstricmp (DSTR dstr1
, DSTR dstr2
)
153 UBYTE temp
[PATHSIZE
];
155 strncpy (temp
,dstr1
,*dstr1
+1);
157 result
= intlcmp (temp
,dstr2
);
162 // BCPLtoCString converts BCPL string to a CString.
163 UBYTE
*BCPLtoCString(STRPTR dest
, DSTR src
)
165 #ifdef AROS_FAST_BSTR
166 strcpy(dest
, (CONST_STRPTR
)src
);
172 len
= min (len
, PATHSIZE
);
176 *(dest
++) = *(src
++);