don't check when its clang masquerading as gcc
[AROS.git] / workbench / c / ResList.c
blobbc8bb3861195d61e31f687201082eb2875f3923f
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 /******************************************************************************
12 NAME
14 ResList
16 SYNOPSIS
18 (N/A)
20 LOCATION
24 FUNCTION
26 Prints a list of all resources.
28 INPUTS
30 RESULT
32 NOTES
34 EXAMPLE
36 BUGS
38 SEE ALSO
40 INTERNALS
42 HISTORY
44 ******************************************************************************/
46 #include <exec/memory.h>
47 #include <exec/tasks.h>
48 #include <exec/execbase.h>
49 #include <proto/exec.h>
50 #include <dos/dosextens.h>
51 #include <proto/dos.h>
53 #if defined(__AROSPLATFORM_SMP__)
54 #include <aros/types/spinlock_s.h>
55 #include <proto/execlock.h>
56 #include <resources/execlock.h>
57 #endif
59 const TEXT version[] = "$VER: reslist 41.3 (11.3.2015)\n";
61 struct res
63 STRPTR name;
64 APTR address;
67 static int addres(struct Node *r, struct res **l, STRPTR *e)
69 STRPTR s1, s2;
71 (*l)->address = r;
73 s1 = r->ln_Name;
75 if(s1!=NULL)
77 s2=s1;
78 while(*s2++)
80 while(s2>s1)
82 if(*e<=(STRPTR)*l)
83 return 0;
84 *--(*e)=*--s2;
87 if((STRPTR)(*l+1)>*e)
88 return 0;
90 (*l)->name=*e;
91 ++*l;
93 return 1;
96 static int fillbuffer(struct res **buffer, IPTR size)
98 #if defined(__AROSPLATFORM_SMP__)
99 void *ExecLockBase = OpenResource("execlock.resource");
100 #endif
101 STRPTR end=(STRPTR)*buffer+size;
102 struct Node *r;
103 #if defined(__AROSPLATFORM_SMP__)
104 if (ExecLockBase)
105 ObtainSystemLock(&SysBase->ResourceList, SPINLOCK_MODE_READ, LOCKF_FORBID);
106 else
107 Forbid();
108 #else
109 Forbid();
110 #endif
111 for(r=(struct Node *)SysBase->ResourceList.lh_Head;
112 r->ln_Succ!=NULL;
113 r=(struct Node *)r->ln_Succ)
115 if(!addres(r,buffer,&end))
117 #if defined(__AROSPLATFORM_SMP__)
118 if (ExecLockBase)
119 ReleaseSystemLock(&SysBase->ResourceList, LOCKF_FORBID);
120 else
121 Permit();
122 #else
123 Permit();
124 #endif
125 return 0;
128 #if defined(__AROSPLATFORM_SMP__)
129 if (ExecLockBase)
130 ReleaseSystemLock(&SysBase->ResourceList, LOCKF_FORBID);
131 else
132 Permit();
133 #else
134 Permit();
135 #endif
136 return 1;
139 int __nocommandline;
141 int main(void)
143 IPTR size;
144 struct res *buffer,*ress,*ress2;
145 for(size=2048;;size+=2048)
147 buffer=AllocVec(size,MEMF_ANY);
148 if(buffer==NULL)
150 FPuts(Output(),"Not Enough memory for library buffer\n");
151 return 20;
153 ress=buffer;
154 if(fillbuffer(&ress,size))
156 #if (__WORDSIZE == 64)
157 FPuts(Output()," Address Name\n");
158 #else
159 FPuts(Output()," Address Name\n");
160 #endif
161 for(ress2=buffer;ress2<ress;ress2++)
163 #if (__WORDSIZE == 64)
164 Printf("0x%012.ix %s\n",
165 #else
166 Printf("0x%08.ix %s\n",
167 #endif
168 ress2->address, ress2->name);
170 FreeVec(buffer);
171 return 0;
173 FreeVec(buffer);