tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / rom / dos / findsegment.c
blob085c9c5e809c6d3cd3a5feeed5a6b7f179402606
1 /*
2 Copyright © 1995-2016, 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"
12 /*****************************************************************************
14 NAME */
15 #include <dos/dosextens.h>
16 #include <proto/dos.h>
18 AROS_LH3(struct Segment *, FindSegment,
20 /* SYNOPSIS */
21 AROS_LHA(CONST_STRPTR , name, D1),
22 AROS_LHA(struct Segment *, seg, D2),
23 AROS_LHA(LONG , system, D3),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 130, Dos)
28 /* FUNCTION
29 Search for a resident segment by name and type (system or user).
30 The first segment that exactly matches the name and type will be
31 returned. The name is case insensitive. If the system argument is
32 non-zero, only system segments will be returned (i.e. those that
33 have a negative seg_UC value); if zero, only user segments will
34 be returned (i.e. those with a non-negative seg_UC value).
36 You can continue searching for multiple segments that share the
37 same name and type by specifying the last returned segment as
38 the seg argument.
40 FindSegment() does no locking of the segment list. You should
41 lock the list by calling Forbid() before calling FindSegment(),
42 and unlock the list by calling Permit() once you have finished
43 calling FindSegment().
45 If you wish to prevent a user segment from being unloaded, you
46 must increment its seg_UC value before unlocking the list. Once
47 finished with the segment, you must decrement its seg_UC value
48 under Forbid()/Permit() protection. The seg_UC value of system
49 segments should never be altered.
51 INPUTS
52 name - Name of the segment to search for.
53 seg - Start search from this point.
54 system - Search for a system segment.
56 RESULT
57 A matching segment, or NULL.
59 NOTES
61 EXAMPLE
63 BUGS
65 SEE ALSO
66 AddSegment(), RemSegment()
68 INTERNALS
70 *****************************************************************************/
72 AROS_LIBFUNC_INIT
74 struct DosInfo *dinf = BADDR(DOSBase->dl_Root->rn_Info);
76 /* Segment seg was the last match, let's start from the next one */
77 if( seg != NULL )
78 seg = BADDR(seg->seg_Next);
79 else
80 seg = BADDR(dinf->di_ResList);
82 while( seg != NULL )
84 D(bug("[FindSegment] Checking segment '%s'\n",
85 AROS_BSTR_ADDR(MKBADDR(&seg->seg_Name[0]))));
88 ((system && seg->seg_UC < 0) || (!system && seg->seg_UC >= 0)) &&
89 (Stricmp( name, AROS_BSTR_ADDR(MKBADDR(&seg->seg_Name[0]))) == 0)
92 /* We have a matching segment */
93 return seg;
95 seg = BADDR(seg->seg_Next);
98 return NULL;
99 AROS_LIBFUNC_EXIT
100 } /* FindSegment */