OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / original / man3 / dlopen.3
index 8d6f80e..b2be52b 100644 (file)
@@ -32,7 +32,7 @@
 .\" Modified by Walter Harms: dladdr, dlvsym
 .\" Modified by Petr Baudis <pasky@suse.cz>, 2008-12-04: dladdr caveat
 .\"
-.TH DLOPEN 3 2008-12-06 "Linux" "Linux Programmer's Manual"
+.TH DLOPEN 3 2014-10-02 "Linux" "Linux Programmer's Manual"
 .SH NAME
 dladdr, dlclose, dlerror, dlopen, dlsym, dlvsym \- programming interface to
 dynamic linking loader
@@ -58,7 +58,7 @@ implement the interface to the dynamic linking loader.
 .SS dlerror()
 The function
 .BR dlerror ()
-returns a human readable string describing the most recent error
+returns a human-readable string describing the most recent error
 that occurred from
 .BR dlopen (),
 .BR dlsym ()
@@ -192,7 +192,7 @@ This flag is not specified in POSIX.1-2001.
 .PP
 If
 .I filename
-is a NULL pointer, then the returned handle is for the main program.
+is NULL, then the returned handle is for the main program.
 When given to
 .BR dlsym (),
 this handle causes a search for a symbol in the main program,
@@ -214,7 +214,7 @@ to resolve references in a dynamically loaded library.
 .PP
 If the same library is loaded again with
 .BR dlopen (),
-the same file handle is returned.
+the same library handle is returned.
 The dl library maintains reference
 counts for library handles, so a dynamic library is not
 deallocated until
@@ -353,8 +353,8 @@ typedef struct {
                                contains address */
     void       *dli_fbase;  /* Address at which shared object
                                is loaded */
-    const char *dli_sname;  /* Name of nearest symbol with address
-                               lower than \fIaddr\fP */
+    const char *dli_sname;  /* Name of symbol whose definition
+                               overlaps \fIaddr\fP */
     void       *dli_saddr;  /* Exact address of symbol named
                                in \fIdli_sname\fP */
 } Dl_info;
@@ -466,17 +466,29 @@ main(int argc, char **argv)
 
     dlerror();    /* Clear any existing error */
 
-    /* Writing: cosine = (double (*)(double)) dlsym(handle, "cos");
-       would seem more natural, but the C99 standard leaves
-       casting from "void *" to a function pointer undefined.
-       The assignment used below is the POSIX.1\-2003 (Technical
-       Corrigendum 1) workaround; see the Rationale for the
-       POSIX specification of dlsym(). */
+    cosine = (double (*)(double)) dlsym(handle, "cos");
+
+    /* According to the ISO C standard, casting between function
+       pointers and 'void *', as done above, produces undefined results.
+       POSIX.1-2003 and POSIX.1-2008 accepted this state of affairs and
+       proposed the following workaround:
+
+           *(void **) (&cosine) = dlsym(handle, "cos");
+
+       This (clumsy) cast conforms with the ISO C standard and will
+       avoid any compiler warnings.
 
-    *(void **) (&cosine) = dlsym(handle, "cos");
-.\" But in fact "gcc -O2 -Wall" will complain about the preceding cast.
+       The 2013 Technical Corrigendum to POSIX.1-2008 (a.k.a.
+       POSIX.1-2013) improved matters by requiring that conforming
+       implementations support casting 'void *' to a function pointer.
+       Nevertheless, some compilers (e.g., gcc with the '-pedantic'
+       option) may complain about the cast used in this program. */
+.\" http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html#tag_03_112_08
+.\" http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html#tag_16_96_07
+.\" http://austingroupbugs.net/view.php?id=74
 
-    if ((error = dlerror()) != NULL)  {
+    error = dlerror();
+    if (error != NULL) {
         fprintf(stderr, "%s\en", error);
         exit(EXIT_FAILURE);
     }
@@ -509,9 +521,19 @@ as the example name:
 .SH SEE ALSO
 .BR ld (1),
 .BR ldd (1),
+.BR pldd (1),
 .BR dl_iterate_phdr (3),
 .BR rtld-audit (7),
 .BR ld.so (8),
 .BR ldconfig (8)
 
 ld.so info pages, gcc info pages, ld info pages
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.