-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsupport.c
180 lines (147 loc) · 3.49 KB
/
support.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* $Id: support.c 10.11 1998/09/27 11:26:37 Michiel Exp Michiel $ */
/* $Log: support.c $
* Revision 10.11 1998/09/27 11:26:37 Michiel
* ErrorMsg extra param.
*
* Revision 10.10 1996/01/30 12:51:14 Michiel
* --- working tree overlap ---
* Free memory functions check for NULL pointers
*
* Revision 10.9 1995/10/04 14:03:17 Michiel
* amigalib memorypools -> support 2.0 too
*
* Revision 10.8 1995/09/01 11:17:41 Michiel
* ErrorMsg adaption (see disk.c and volume.c)
*
* Revision 10.7 1995/08/04 11:50:37 Michiel
* From default allocate-retry to default not-retry-but-fail
*
* Revision 10.6 1995/07/21 06:57:10 Michiel
* fixed bug in AllocBufmemR (double size registration)
*
* Revision 10.5 1995/07/11 17:29:31 Michiel
* ErrorMsg () calls use messages.c variables now.
*
* Revision 10.4 1995/06/16 10:02:17 Michiel
* added pool for buffer memory
*
* Revision 10.3 1995/06/15 18:56:21 Michiel
* pooled mem
* functions added
*
* Revision 10.2 1995/01/29 07:34:57 Michiel
* Minor changes
*
* Revision 10.1 1994/10/24 11:16:28 Michiel
* first RCS revision
* */
#include <exec/types.h>
#include <clib/alib_protos.h>
#include "kswrapper.h"
static void OutOfMemory (globaldata *g);
/*
* Allocate from main pool (type MEMF_CLEAR)
* without retry
*/
void *AllocPooledVec (ULONG size, globaldata *g)
{
ULONG *buffer;
buffer = LibAllocPooled (g->mainPool, size+sizeof(ULONG));
if (buffer)
*buffer++ = size;
return buffer;
}
void FreePooledVec (void *mem, globaldata *g)
{
if (mem)
LibFreePooled (g->mainPool, (ULONG *)mem - 1, *((ULONG *)mem - 1) + sizeof(ULONG));
}
/*
* Buffer allocation
*/
void *AllocPooledBuf (ULONG size, globaldata *g)
{
ULONG *buffer;
buffer = LibAllocPooled (g->bufferPool, size+sizeof(ULONG));
if (buffer)
*buffer++ = size;
if (((IPTR)buffer) & ~g->dosenvec->de_Mask)
ErrorMsg (AFS_WARNING_MEMORY_MASK, NULL, g);
return buffer;
}
void FreePooledBuf (void *mem, globaldata *g)
{
if (mem)
LibFreePooled (g->bufferPool, (ULONG *)mem - 1, *((ULONG *)mem - 1) + sizeof(ULONG));
}
/*
* retrying variants of 'globaldata' allocation functions
*/
void *AllocMemPR (ULONG size, globaldata *g)
{
ULONG *buffer;
while (!(buffer = AllocMemP (size, g)))
OutOfMemory (g);
return buffer;
}
void *AllocBufmemR (ULONG size, globaldata *g)
{
ULONG *buffer;
while (!(buffer = AllocBufmem (size, g)))
OutOfMemory (g);
return buffer;
}
/*
* Retrying AllocVec
*/
VOID *AllocMemR (ULONG size, ULONG flags, globaldata *g)
{
UBYTE *buffer;
while (!(buffer=AllocVec (size, flags)))
{
OutOfMemory (g);
}
return buffer;
}
static void OutOfMemory (globaldata *g)
{
FreeUnusedResources (g->currentvolume, g);
NormalErrorMsg (AFS_ERROR_PLEASE_FREE_MEM, NULL, 1); // I MUST have memory!
}
/* SUPPORTFUNCTION dstricmp
** TRUE: dstring == cstring
** FALSE: cstring <> cstring
*/
BOOL dstricmp (DSTR dstring, STRPTR cstring)
{
BOOL result;
UBYTE temp[PATHSIZE];
ctodstr (cstring, temp);
intltoupper (temp);
result = intlcmp (temp, dstring);
return result;
}
/* ddstricmp
** compare two dstrings
*/
BOOL ddstricmp (DSTR dstr1, DSTR dstr2)
{
BOOL result;
UBYTE temp[PATHSIZE];
strncpy (temp,dstr1,*dstr1+1);
intltoupper (temp);
result = intlcmp (temp,dstr2);
return result;
}
// BCPLtoCString converts BCPL string to a CString.
UBYTE *BCPLtoCString(STRPTR dest, DSTR src)
{
UBYTE len, *to;
len = *(src++);
len = min (len, PATHSIZE);
to = dest;
while (len--)
*(dest++) = *(src++);
*dest = 0x0;
return to;
}