#!/bin/sh # This is a shell archive (shar 3.24) # made 05/25/1993 16:42 UTC by jum@osiris # Source directory /home/jum/dyn/hppa # # existing files WILL be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 634 -rw-rw-rw- Makefile # 696 -r--r--r-- dlfcn.h # 3401 -r--r--r-- dlfcn.c # if touch 2>&1 | fgrep '[-amc]' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= Makefile ============== echo "x - extracting Makefile (Text)" sed 's/^X//' << 'SHAR_EOF' > Makefile && X# %W% revision of %E% %U% X# This is an unpublished work copyright (c) 1992 Helios Software GmbH X# 3000 Hannover 1, West Germany X XSHELL=/bin/sh XCC=cc -Aa +ESlit XIPATH= XDEFS=-D_HPUX_SOURCE XDEBUGFLAGS=-g -DDEBUG XNODEBUGFLAGS=-O XCFLAGS=$(IPATH) $(DEFS) $(NODEBUGFLAGS) XTARGETS=libdl.a XDEST=/usr/local/lib XHDRS=dlfcn.h XSRCS=dlfcn.c XOBJS=$(SRCS:%.c=%.o) X Xall: $(TARGETS) dlfcn.c X X$(TARGETS): $(OBJS) X ar rv $@ $? X Xdlfcn.o: dlfcn.h X Xlint: X lint $(IPATH) $(DEFS) $(SRCS) >lintout X Xinfo: X sccs info X Xclean: X rm -f lintout a.out core *.o *-lg *% *~ tags deps% X Xclobber: clean X rm -f $(TARGETS) deps X Xinstall: all X cp $(TARGETS) $(DEST) SHAR_EOF $TOUCH -am 0214190093 Makefile && chmod 0666 Makefile || echo "restore of Makefile failed" set `wc -c Makefile`;Wc_c=$1 if test "$Wc_c" != "634"; then echo original size 634, current size $Wc_c fi # ============= dlfcn.h ============== echo "x - extracting dlfcn.h (Text)" sed 's/^X//' << 'SHAR_EOF' > dlfcn.h && X/* X * @(#)dlfcn.h 1.3 revision of 92/12/27 20:58:32 X * This is an unpublished work copyright (c) 1992 Helios Software GmbH X * 3000 Hannover 1, Germany X */ X X/* X * Mode flags for the dlopen routine. X */ X#define RTLD_LAZY 1 X#define RTLD_NOW 2 X X/* X * To be able to intialize, a library may provide a dl_info structure X * that contains functions to be called to initialize and terminate. X */ Xstruct dl_info { X void (*init)(void); X void (*fini)(void); X}; X X#if __STDC__ || defined(_IBMR2) Xvoid *dlopen(const char *path, int mode); Xvoid *dlsym(void *handle, const char *symbol); Xchar *dlerror(void); Xint dlclose(void *handle); X#else Xvoid *dlopen(); Xvoid *dlsym(); Xchar *dlerror(); Xint dlclose(); X#endif SHAR_EOF $TOUCH -am 0214190993 dlfcn.h && chmod 0444 dlfcn.h || echo "restore of dlfcn.h failed" set `wc -c dlfcn.h`;Wc_c=$1 if test "$Wc_c" != "696"; then echo original size 696, current size $Wc_c fi # ============= dlfcn.c ============== echo "x - extracting dlfcn.c (Text)" sed 's/^X//' << 'SHAR_EOF' > dlfcn.c && X/* X * @(#)dlfcn.c 1.2 revision of 93/02/26 09:38:22 X * This is an unpublished work copyright (c) 1993 HELIOS Software GmbH X * 3000 Hannover 1, Germany X */ X X#include X#include X#include X#include X#include X#include "dlfcn.h" X X/* X * The void * handle returned from dlopen is actually a ModulePtr. X */ Xtypedef struct Module { X struct Module *next; X char *name; /* module name for refcounting */ X int refCnt; /* the number of references */ X shl_t shlHandle; /* library handle from shl_load */ X struct dl_info *info; /* optional init/terminate functions */ X} Module, *ModulePtr; X X/* X * We keep a list of all loaded modules to be able to call the fini X * handlers at atexit() time. X */ Xstatic ModulePtr modList; X X/* X * The last error from one of the dl* routines is kept in static X * variables here. Each error is returned only once to the caller. X */ Xstatic char errbuf[BUFSIZ]; Xstatic int errvalid; X Xextern char *strdup(const char *); Xstatic void terminate(void); X X/* ARGSUSED */ Xvoid *dlopen(const char *path, int mode) X{ X register ModulePtr mp; X static int beenHere = 0; X X /* X * Upon the first call register a terminate handler that will X * close all libraries. X */ X if (!beenHere) { X beenHere = 1; X atexit(terminate); X } X /* X * Scan the list of modules if have the module already loaded. X */ X for (mp = modList; mp; mp = mp->next) X if (strcmp(mp->name, path) == 0) { X mp->refCnt++; X return mp; X } X if ((mp = (ModulePtr)calloc(1, sizeof(*mp))) == NULL) { X errvalid++; X strcpy(errbuf, "calloc: "); X strcat(errbuf, strerror(errno)); X return NULL; X } X if ((mp->name = strdup(path)) == NULL) { X errvalid++; X strcpy(errbuf, "strdup: "); X strcat(errbuf, strerror(errno)); X free(mp); X return NULL; X } X if ((mp->shlHandle = shl_load((char *)path, X (mode == RTLD_NOW ? BIND_IMMEDIATE : BIND_DEFERRED)|BIND_FIRST, X NULL)) == NULL) { X free(mp->name); X free(mp); X errvalid++; X strcpy(errbuf, "dlopen: "); X strcat(errbuf, path); X strcat(errbuf, ": "); X strcat(errbuf, strerror(errno)); X return NULL; X } X mp->refCnt = 1; X mp->next = modList; X modList = mp; X /* X * If there is a dl_info structure, call the init function. X */ X if (mp->info = (struct dl_info *)dlsym(mp, "dl_info")) { X if (mp->info->init) X (*mp->info->init)(); X } else X errvalid = 0; X return mp; X} X Xvoid *dlsym(void *handle, const char *symbol) X{ X register ModulePtr mp = (ModulePtr)handle; X shl_t tmp = mp->shlHandle; X long val; X X if (shl_findsym(&tmp, (char *)symbol, TYPE_UNDEFINED, &val) == -1) { X errvalid++; X strcpy(errbuf, "dlsym: "); X strcat(errbuf, symbol); X strcat(errbuf, ": "); X strcat(errbuf, strerror(errno)); X return NULL; X } X return (void *)val; X} X Xchar *dlerror(void) X{ X if (errvalid) { X errvalid = 0; X return errbuf; X } X return NULL; X} X Xint dlclose(void *handle) X{ X register ModulePtr mp = (ModulePtr)handle; X int result; X register ModulePtr mp1; X X if (--mp->refCnt > 0) X return 0; X if (mp->info && mp->info->fini) X (*mp->info->fini)(); X result = shl_unload(mp->shlHandle); X if (result == -1) { X errvalid++; X strcpy(errbuf, strerror(errno)); X } X if (mp == modList) X modList = mp->next; X else { X for (mp1 = modList; mp1; mp1 = mp1->next) X if (mp1->next == mp) { X mp1->next = mp->next; X break; X } X } X free(mp->name); X free(mp); X return result; X} X Xstatic void terminate(void) X{ X while (modList) X dlclose(modList); X} SHAR_EOF $TOUCH -am 0226094093 dlfcn.c && chmod 0444 dlfcn.c || echo "restore of dlfcn.c failed" set `wc -c dlfcn.c`;Wc_c=$1 if test "$Wc_c" != "3401"; then echo original size 3401, current size $Wc_c fi exit 0