Call CloseDevice() before DeleteIORequest(), and don't call
[AROS.git] / rom / dos / findsegment.c
blob7b08fcc3c43cee460480178057aa5e76eb0bb37d
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Find a resident segment.
6 Lang: english
7 */
8 #include "dos_intern.h"
9 #include <string.h>
11 /*****************************************************************************
13 NAME */
14 #include <dos/dosextens.h>
15 #include <proto/dos.h>
17 AROS_LH3(struct Segment *, FindSegment,
19 /* SYNOPSIS */
20 AROS_LHA(CONST_STRPTR , name, D1),
21 AROS_LHA(struct Segment *, seg, D2),
22 AROS_LHA(BOOL , system, D3),
24 /* LOCATION */
25 struct DosLibrary *, DOSBase, 130, Dos)
27 /* FUNCTION
28 Search for a resident segment by name and type. FindSegment() will
29 return the first segment that exactly matches the name and type.
31 You can continue searching by specifying the last returned segment
32 as the seg argument.
34 INPUTS
35 name - Name of the segment to search for.
36 seg - Start search from this point.
37 system - Search for a system segment.
39 RESULT
40 Will return the segment structure if a match is found, otherwise
41 will return NULL.
43 NOTES
44 FindSegment() does no locking of the segment list. You should
45 lock yourself. FindSegment() also does not increment the value
46 of the seg_UC field. If the value of seg_UC > 0, you MUST
47 perform user counting in order to prevent the segment from being
48 unloaded.
50 EXAMPLE
52 BUGS
54 SEE ALSO
55 AddSegment(), RemSegment()
57 INTERNALS
59 *****************************************************************************/
61 AROS_LIBFUNC_INIT
63 struct DosInfo *dinf = BADDR(DOSBase->dl_Root->rn_Info);
65 /* Segment seg was the last match, lets start from the next one */
66 if( seg != NULL )
67 seg = BADDR(seg->seg_Next);
68 else
69 seg = BADDR(dinf->di_ResList);
71 while( seg != NULL )
75 (system || (system == FALSE && (seg->seg_UC >=0))) &&
76 (Stricmp( name, AROS_BSTR_ADDR(MKBADDR(&seg->seg_Name[0]))) == 0)
79 /* We have a matching segment */
80 return seg;
82 seg = BADDR(seg->seg_Next);
85 return NULL;
86 AROS_LIBFUNC_EXIT
87 } /* FindSegment */