update gcc 5 patch for 20150222 snapshot
[AROS.git] / rom / dos / findsegment.c
blob23351aad5c6335df4b30470751a26f3256e4cb51
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Find a resident segment.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include "dos_intern.h"
11 #include <string.h>
13 /*****************************************************************************
15 NAME */
16 #include <dos/dosextens.h>
17 #include <proto/dos.h>
19 AROS_LH3(struct Segment *, FindSegment,
21 /* SYNOPSIS */
22 AROS_LHA(CONST_STRPTR , name, D1),
23 AROS_LHA(struct Segment *, seg, D2),
24 AROS_LHA(BOOL , system, D3),
26 /* LOCATION */
27 struct DosLibrary *, DOSBase, 130, Dos)
29 /* FUNCTION
30 Search for a resident segment by name and type. FindSegment() will
31 return the first segment that exactly matches the name and type.
33 You can continue searching by specifying the last returned segment
34 as the seg argument.
36 INPUTS
37 name - Name of the segment to search for.
38 seg - Start search from this point.
39 system - Search for a system segment.
41 RESULT
42 Will return the segment structure if a match is found, otherwise
43 will return NULL.
45 NOTES
46 FindSegment() does no locking of the segment list. You should
47 lock yourself. FindSegment() also does not increment the value
48 of the seg_UC field. If the value of seg_UC > 0, you MUST
49 perform user counting in order to prevent the segment from being
50 unloaded.
52 EXAMPLE
54 BUGS
56 SEE ALSO
57 AddSegment(), RemSegment()
59 INTERNALS
61 *****************************************************************************/
63 AROS_LIBFUNC_INIT
65 struct DosInfo *dinf = BADDR(DOSBase->dl_Root->rn_Info);
67 /* Segment seg was the last match, let's start from the next one */
68 if( seg != NULL )
69 seg = BADDR(seg->seg_Next);
70 else
71 seg = BADDR(dinf->di_ResList);
73 while( seg != NULL )
75 D(bug("[FindSegment] Checking segment '%s'\n",
76 AROS_BSTR_ADDR(MKBADDR(&seg->seg_Name[0]))));
79 (system || (system == FALSE && (seg->seg_UC >=0))) &&
80 (Stricmp( name, AROS_BSTR_ADDR(MKBADDR(&seg->seg_Name[0]))) == 0)
83 /* We have a matching segment */
84 return seg;
86 seg = BADDR(seg->seg_Next);
89 return NULL;
90 AROS_LIBFUNC_EXIT
91 } /* FindSegment */