genmodule: Fix handler modules types' initialization
[AROS.git] / rom / filesys / pfs3 / fs / support.c
blobea099c17d0289a46de7b82613a182dbadffcd230
1 /* $Id: support.c 10.11 1998/09/27 11:26:37 Michiel Exp Michiel $ */
2 /* $Log: support.c $
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
29 * pooled mem
30 * functions added
32 * Revision 10.2 1995/01/29 07:34:57 Michiel
33 * Minor changes
35 * Revision 10.1 1994/10/24 11:16:28 Michiel
36 * first RCS revision
37 * */
39 static void OutOfMemory (globaldata *g);
42 * Allocate from main pool (type MEMF_CLEAR)
43 * without retry
45 void *AllocPooledVec (ULONG size, globaldata *g)
47 ULONG *buffer;
49 buffer = LibAllocPooled (g->mainPool, size+sizeof(ULONG));
50 if (buffer)
51 *buffer++ = size;
53 return buffer;
56 void FreePooledVec (void *mem, globaldata *g)
58 if (mem)
59 LibFreePooled (g->mainPool, (ULONG *)mem - 1, *((ULONG *)mem - 1) + sizeof(ULONG));
63 * Buffer allocation
65 void *AllocPooledBuf (ULONG size, globaldata *g)
67 ULONG *buffer;
69 buffer = LibAllocPooled (g->bufferPool, size+sizeof(ULONG));
70 if (buffer)
71 *buffer++ = size;
73 if (((IPTR)buffer) & ~g->dosenvec->de_Mask)
74 ErrorMsg (AFS_WARNING_MEMORY_MASK, NULL, g);
76 return buffer;
79 void FreePooledBuf (void *mem, globaldata *g)
81 if (mem)
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)
91 ULONG *buffer;
93 while (!(buffer = AllocMemP (size, g)))
94 OutOfMemory (g);
96 return buffer;
99 void *AllocBufmemR (ULONG size, globaldata *g)
101 ULONG *buffer;
103 while (!(buffer = AllocBufmem (size, g)))
104 OutOfMemory (g);
106 return buffer;
110 * Retrying AllocVec
112 VOID *AllocMemR (ULONG size, ULONG flags, globaldata *g)
114 UBYTE *buffer;
116 while (!(buffer=AllocVec (size, flags)))
118 OutOfMemory (g);
119 NormalErrorMsg (AFS_ERROR_PLEASE_FREE_MEM, NULL, 1); // I MUST have memory!
122 return buffer;
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)
138 BOOL result;
139 UBYTE temp[PATHSIZE];
141 ctodstr (cstring, temp);
142 intltoupper (temp);
143 result = intlcmp (temp, dstring);
144 return result;
147 /* ddstricmp
148 ** compare two dstrings
150 BOOL ddstricmp (DSTR dstr1, DSTR dstr2)
152 BOOL result;
153 UBYTE temp[PATHSIZE];
155 strncpy (temp,dstr1,*dstr1+1);
156 intltoupper (temp);
157 result = intlcmp (temp,dstr2);
158 return result;
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);
167 return dest;
168 #else
169 UBYTE len, *to;
171 len = *(src++);
172 len = min (len, PATHSIZE);
173 to = dest;
175 while (len--)
176 *(dest++) = *(src++);
177 *dest = 0x0;
179 return to;
180 #endif