Merging NList MCC 0.119 into the main branch.
[AROS.git] / rom / misc / allocmiscresource.c
blob16fc232506d1856add3971755d1adca9cef90b07
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: AllocMiscResource() function.
6 Lang: English
7 */
8 #include "misc_intern.h"
9 #include <proto/exec.h>
10 #include <resources/misc.h>
12 /*****************************************************************************
14 NAME */
16 AROS_LH2(char *, AllocMiscResource,
18 /* SYNOPSIS */
19 AROS_LHA(ULONG, unitNum, D0),
20 AROS_LHA(char *, name, A0),
22 /* LOCATION */
23 APTR, MiscBase, 1, Misc)
25 /* FUNCTION
27 Allocates one of the miscellaneous resources.
29 INPUTS
31 unitNum -- The resource to allocate
32 name -- An identifying name for you, must NOT be NULL.
34 RESULT
36 NULL if the allocation was successful. If the resource couln't be
37 allocated, the name of the holder of the resource is returned.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 FreeMiscResource()
49 INTERNALS
51 The misc.resource should probably just redirect commands to a HIDD
52 in the future, to support things like multiple serial ports.
54 HISTORY
56 *****************************************************************************/
58 AROS_LIBFUNC_INIT
60 char *errorStr = "Error -- invalid unit.";
61 char *retval;
63 if(unitNum >= MR_MAXUNIT)
64 return errorStr;
66 ObtainSemaphore(&GPB(MiscBase)->mb_Lock);
68 retval = GPB(MiscBase)->mb_owners[unitNum];
70 if(retval == NULL)
71 GPB(MiscBase)->mb_owners[unitNum] = name;
73 ReleaseSemaphore(&GPB(MiscBase)->mb_Lock);
75 return retval;
77 AROS_LIBFUNC_EXIT
78 } /* AllocMiscResource */