1DLCLOSE(P)                 POSIX Programmer's Manual                DLCLOSE(P)
2
3
4

NAME

6       dlclose - close a dlopen object
7

SYNOPSIS

9       #include <dlfcn.h>
10
11       int dlclose(void *handle);
12
13

DESCRIPTION

15       The  dlclose()  function shall inform the system that the object refer‐
16       enced by a handle returned from a previous dlopen()  invocation  is  no
17       longer needed by the application.
18
19       The  use of dlclose() reflects a statement of intent on the part of the
20       process, but does not create any requirement upon  the  implementation,
21       such  as  removal  of the code or symbols referenced by handle. Once an
22       object has been closed using dlclose()  an  application  should  assume
23       that its symbols are no longer available to dlsym(). All objects loaded
24       automatically as a result of invoking dlopen() on the referenced object
25       shall also be closed if this is the last reference to it.
26
27       Although  a  dlclose()  operation  is not required to remove structures
28       from an address space, neither is  an  implementation  prohibited  from
29       doing  so.  The  only  restriction  on such a removal is that no object
30       shall be removed to which references  have  been  relocated,  until  or
31       unless  all  such  references are removed. For instance, an object that
32       had been loaded with a dlopen() operation  specifying  the  RTLD_GLOBAL
33       flag  might  provide  a target for dynamic relocations performed in the
34       processing of other objects-in such environments,  an  application  may
35       assume  that no relocation, once made, shall be undone or remade unless
36       the object requiring the relocation has itself been removed.
37

RETURN VALUE

39       If the referenced  object  was  successfully  closed,  dlclose()  shall
40       return  0.  If  the  object  could not be closed, or if handle does not
41       refer to an open object, dlclose() shall return a non-zero value.  More
42       detailed diagnostic information shall be available through dlerror().
43

ERRORS

45       No errors are defined.
46
47       The following sections are informative.
48

EXAMPLES

50       The following example illustrates use of dlopen() and dlclose():
51
52
53              ...
54              /* Open a dynamic library and then close it ... */
55
56
57              #include <dlfcn.h>
58              void *mylib;
59              int eret;
60
61
62              mylib = dlopen("mylib.so", RTLD_LOCAL | RTLD_LAZY);
63              ...
64              eret = dlclose(mylib);
65              ...
66

APPLICATION USAGE

68       A  conforming  application  should  employ  a  handle  returned  from a
69       dlopen() invocation only within a given scope bracketed by the dlopen()
70       and  dlclose()  operations.  Implementations  are free to use reference
71       counting or other techniques such that multiple calls to dlopen()  ref‐
72       erencing the same object may return the same object for handle.  Imple‐
73       mentations are also free to reuse a  handle.  For  these  reasons,  the
74       value  of  a handle must be treated as an opaque object by the applica‐
75       tion, used only in calls to dlsym() and dlclose().
76

RATIONALE

78       None.
79

FUTURE DIRECTIONS

81       None.
82

SEE ALSO

84       dlerror() , dlopen()  ,  dlsym()  ,  the  Base  Definitions  volume  of
85       IEEE Std 1003.1-2001, <dlfcn.h>
86
88       Portions  of  this text are reprinted and reproduced in electronic form
89       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
90       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
91       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
92       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
93       event of any discrepancy between this version and the original IEEE and
94       The  Open Group Standard, the original IEEE and The Open Group Standard
95       is the referee document. The original Standard can be  obtained  online
96       at http://www.opengroup.org/unix/online.html .
97
98
99
100IEEE/The Open Group                  2003                           DLCLOSE(P)
Impressum