dlgetfileinfo.3c (2010 09)

d
dlgetfileinfo(3C) dlgetfileinfo(3C)
NAME
dlgetfileinfo() - return file information for a library prior to loading it
SYNOPSIS
cc [flag... ] file...
-ldl [library ]...
#include <dlfcn.h>
uint64_t dlgetfileinfo(const char *file,
size_t info_size,
struct dlfileinfo *info);
Multithread Usage
This routine is thread-safe.
DESCRIPTION
dlgetfileinfo()
is one of a family of routines that give the user direct access to the dynamic linking
facilities (using the
-ldl option on the compiler or
ld command line). dlgetfileinfo()
returns file
information for a library prior to loading it. This information can be used to allocate load segments
before calling
dlopene().
file is used to construct a path name to the library. The dynamic loader searches for the library using the
standard search rules used by
dlopen() and dlopene(). If the library is found and is a valid shared
library, dlgetfileinfo returns information about the library through the info parameter.
info_size is the size in bytes of the info buffer.
info is a pointer to a buffer allocated by the user program. The dynamic loader fills this buffer with file
information.
A dlfileinfo structure has the following members:
struct dlfileinfo {
size_t text_size;
size_t data_size;
char *filename;
}
text_size is the size in bytes of a shared library’s text segment.
data_size is the size in bytes of a shared library’s data segment.
filename is the path to the shared library. This path may be passed to a subsequent
dlopen() or dlo-
pene() call to avoid searching for the library a second time. The caller of dlgetfileinfo()
must
copy the value of filename to insure that it is not corrupted.
EXAMPLES
The following example illustrates the use of
dlgetfileinfo()
to allocate memory for mapping a
shared library’s data segment. For simplicity, error checking has been omitted.
#include <dlfcn.h>
#include <string.h>
/* allocate_data is a user-supplied routine that allocates a
* a memory buffer of at least "data_size" bytes and returns
* a pointer to the buffer.
*/
extern char *allocate_data(size_t data_size);
int main() {
void *handle;
int status;
char *pathname;
struct dlfileinfo info;
struct dlopen_opts opts;
/* Locate library and get file information */
status = dlgetfileinfo("mylib.so", sizeof(info), &info);
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)