home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / sources / 2899 < prev    next >
Encoding:
Internet Message Format  |  1992-12-29  |  26.8 KB

  1. Path: sparky!uunet!mcsun!sun4nl!cwi.nl!guido
  2. From: guido@cwi.nl (Guido van Rossum)
  3. Newsgroups: alt.sources
  4. Subject: dl-dld 1.1 (dynamic loading interface)
  5. Message-ID: <8476@charon.cwi.nl>
  6. Date: 29 Dec 92 13:03:37 GMT
  7. Sender: news@cwi.nl
  8. Lines: 915
  9.  
  10. Archive-name: dl-dld/part01
  11. Submitted-by: Guido.van.Rossum@cwi.nl
  12. Version: 1.1
  13.  
  14. Almost a year ago I posted version 1.0 of this little library, which
  15. mimics the interface of Jack Jansen's "dl" package (dynamic loading
  16. for the SGI) on top of Wilson Ho's (GNU) dynamic loading package
  17. "dld", version 3.2.3 (dynamic loading for several other systems).
  18.  
  19. Version 1.1 adds two features that are new in Jack's dl:
  20. dl_setmessage() and dl_loadlod_mult().  I'd like to thank Martin-D.
  21. Lacasse for the latter contribution.
  22.  
  23. (If you don't know where to get dld, try anonymous ftp to
  24. wuarchive.wustl.edu:/mirrors2/gnu/dld-3.2.3.tar.Z.  Jack's dld can be
  25. found at ftp.cwi.nl:/pub/dl-1.5.tar.Z.)
  26.  
  27. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  28.  
  29. #! /bin/sh
  30. # This is a shell archive.  Remove anything before this line, then unpack
  31. # it by saving it into a file and typing "sh file".  To overwrite existing
  32. # files, type "sh file -c".  You can also feed this as standard input via
  33. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  34. # will see the following message at the end:
  35. #        "End of archive 1 (of 1)."
  36. # Contents:  MANIFEST Makefile README dl.h dl_error.c dl_findlibs.c
  37. #   dl_getbinary.c dl_loadmod.c strerror.c test test/Makefile
  38. #   test/sub.c test/sub.libs test/sub2.c test/test.c
  39. # Wrapped by guido@voorn.cwi.nl on Tue Dec 29 13:52:21 1992
  40. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  41. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  42.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  43. else
  44. echo shar: Extracting \"'MANIFEST'\" \(810 characters\)
  45. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  46. X   File Name        Archive #    Description
  47. X-----------------------------------------------------------
  48. X MANIFEST                   1    This shipping list
  49. X Makefile                   1    Build recipe
  50. X README                     1    Explanation of what this is
  51. X dl.h                       1    Interface header file
  52. X dl_error.c                 1    Error interface
  53. X dl_findlibs.c              1    Function to read a ".libs" file
  54. X dl_getbinary.c             1    Function to turn argv[0] into a pathname
  55. X dl_loadmod.c               1    The main function
  56. X strerror.c                 1    A PD re-implementation of ANSI C strerror()
  57. X test                       1    Test program subdirectory
  58. X test/Makefile              1    
  59. X test/sub.c                 1    
  60. X test/sub.libs              1    
  61. X test/sub2.c                1    
  62. X test/test.c                1    
  63. END_OF_FILE
  64. if test 810 -ne `wc -c <'MANIFEST'`; then
  65.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  66. fi
  67. # end of 'MANIFEST'
  68. fi
  69. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  70.   echo shar: Will not clobber existing file \"'Makefile'\"
  71. else
  72. echo shar: Extracting \"'Makefile'\" \(429 characters\)
  73. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  74. X# You may have to change this definition of where dld is...
  75. XDLD=        ../dld-3.2.3
  76. XOBJS=        dl_loadmod.o dl_getbinary.o dl_findlibs.o dl_error.o strerror.o
  77. XCFLAGS=        -g -I$(DLD)
  78. XCC=        gcc
  79. X
  80. Xlibdl.a:    $(OBJS)
  81. X        ar crv libdl.a $(OBJS)
  82. X        ranlib libdl.a
  83. X
  84. X$(OBJS):    dl.h
  85. Xdl_loadmod.o:    $(DLD)/dld.h
  86. X
  87. Xclean::
  88. X        -rm -f *.o core [,#@]* *~ *.orig *.old *.bak *.BAK \
  89. X            nohup.out Part??
  90. X
  91. Xclobber::    clean
  92. X        -rm -f lib*.a tags TAGS
  93. X
  94. Xkit::
  95. X        makekit -m
  96. END_OF_FILE
  97. if test 429 -ne `wc -c <'Makefile'`; then
  98.     echo shar: \"'Makefile'\" unpacked with wrong size!
  99. fi
  100. # end of 'Makefile'
  101. fi
  102. if test -f 'README' -a "${1}" != "-c" ; then 
  103.   echo shar: Will not clobber existing file \"'README'\"
  104. else
  105. echo shar: Extracting \"'README'\" \(1601 characters\)
  106. sed "s/^X//" >'README' <<'END_OF_FILE'
  107. XThis is dl-dld, a dynamic linking interface, version 1.1.
  108. X
  109. XDl-dld is a re-implementation of the high-level *interface* of Jack
  110. XJansen's "dl" dynamic loading package, on top of the *implementation*
  111. Xof Wilson Ho's (GNU) dynamic loading package "dld" (version 3.2.3).
  112. X
  113. XThis makes it possible to write programs with simple dynamic loading
  114. Xrequirements (just load a module and call a function from it; no
  115. Xunloading facilities) to run without source changes (using the dl
  116. Xinterface) on a larger number of platforms: using the original dl on
  117. XSGI MIPS machines (Irix 4.0), and using dl-dld on DEC VAX (Ultrix),
  118. XSun 3 (SunOS 3.4 and 4.0), Sparc (SunOS 4.0), Sequent Symmetry (Dynix)
  119. Xand Atari ST.
  120. X
  121. XVersion 1.1 adds the function dl_loadmod_mult(), which was added to dl,
  122. Xand fixes a tiny memory leak -- thanks to Martin-D. Lacasse for this
  123. Xcontribution.
  124. X
  125. XTo build dl-dld, edit the DLD path definition in the Makefile and type
  126. Xmake.
  127. X
  128. XTo use dl-dld, you must link with both ./libdl.a and (...)/libdld.a.
  129. XYou must also avoid sing shared libraries, as dld doesn't (yet)
  130. Xunderstand them.  This is a price you have to pay to use dynamic
  131. Xloading.  On SunOS, this boils down to linking with -Bstatic unless
  132. Xyou use gcc, since gcc also doesn't understand shared libraries.
  133. X
  134. XOf course, the low-level interface of Jack's dl package is not
  135. Ximplemented in dl-dld.
  136. X
  137. X(If you don't know where to get dld, try anonymous ftp to
  138. Xwuarchive.wustl.edu:/mirrors2/gnu/dld-3.2.3.tar.Z.  Jack's dld can be
  139. Xfound at ftp.cwi.nl:/pub/dl-<version>.tar.Z, where <version> is
  140. Xcurrently 1.5.)
  141. X
  142. X--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
  143. END_OF_FILE
  144. if test 1601 -ne `wc -c <'README'`; then
  145.     echo shar: \"'README'\" unpacked with wrong size!
  146. fi
  147. # end of 'README'
  148. fi
  149. if test -f 'dl.h' -a "${1}" != "-c" ; then 
  150.   echo shar: Will not clobber existing file \"'dl.h'\"
  151. else
  152. echo shar: Extracting \"'dl.h'\" \(1979 characters\)
  153. sed "s/^X//" >'dl.h' <<'END_OF_FILE'
  154. X/***********************************************************
  155. XCopyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
  156. XNetherlands.
  157. X
  158. X                        All Rights Reserved
  159. X
  160. XPermission to use, copy, modify, and distribute this software and its 
  161. Xdocumentation for any purpose and without fee is hereby granted, 
  162. Xprovided that the above copyright notice appear in all copies and that
  163. Xboth that copyright notice and this permission notice appear in 
  164. Xsupporting documentation, and that the names of Stichting Mathematisch
  165. XCentrum or CWI not be used in advertising or publicity pertaining to
  166. Xdistribution of the software without specific, written prior permission.
  167. X
  168. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  169. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  170. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  171. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  172. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  173. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  174. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  175. X
  176. X******************************************************************/
  177. X/*
  178. X** Definitions of dl library modules.
  179. X*/
  180. X
  181. X#ifdef __STDC__
  182. X#define _PROTO(x) x
  183. X#else
  184. X#define _PROTO(x) ()
  185. X#endif
  186. X
  187. Xtypedef void dl_errortype _PROTO((char *));
  188. Xtypedef void (*dl_funcptr) _PROTO((void));
  189. X
  190. Xdl_funcptr dl_loadmod _PROTO((char *, char *, char *));
  191. Xvoid dl_error(); /* _PROTO((char *, int)); /* XXX Should use varargs/starg */
  192. Xvoid dl_message(); /* _PROTO((char *, int)); /* XXX Should use varargs/starg */
  193. Xextern dl_errortype dl_defaulterror; /* These are functions! */
  194. Xextern dl_errortype dl_defaultmessage;
  195. Xextern dl_errortype dl_nomessage;
  196. Xvoid dl_setmessage _PROTO((dl_errortype *));
  197. Xvoid dl_seterror _PROTO((dl_errortype *));
  198. X
  199. X/* Internal */
  200. Xchar *dl_findlibs _PROTO((char *));
  201. Xchar *dl_getbinaryname _PROTO((char *));
  202. X
  203. X#undef _PROTO
  204. END_OF_FILE
  205. if test 1979 -ne `wc -c <'dl.h'`; then
  206.     echo shar: \"'dl.h'\" unpacked with wrong size!
  207. fi
  208. # end of 'dl.h'
  209. fi
  210. if test -f 'dl_error.c' -a "${1}" != "-c" ; then 
  211.   echo shar: Will not clobber existing file \"'dl_error.c'\"
  212. else
  213. echo shar: Extracting \"'dl_error.c'\" \(2247 characters\)
  214. sed "s/^X//" >'dl_error.c' <<'END_OF_FILE'
  215. X/***********************************************************
  216. XCopyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
  217. XNetherlands.
  218. X
  219. X                        All Rights Reserved
  220. X
  221. XPermission to use, copy, modify, and distribute this software and its 
  222. Xdocumentation for any purpose and without fee is hereby granted, 
  223. Xprovided that the above copyright notice appear in all copies and that
  224. Xboth that copyright notice and this permission notice appear in 
  225. Xsupporting documentation, and that the names of Stichting Mathematisch
  226. XCentrum or CWI not be used in advertising or publicity pertaining to
  227. Xdistribution of the software without specific, written prior permission.
  228. X
  229. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  230. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  231. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  232. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  233. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  234. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  235. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  236. X
  237. X******************************************************************/
  238. X/*
  239. X** dl_error - dl error handling.
  240. X*/
  241. X
  242. X#include "dl.h"
  243. X#include <stdio.h>
  244. X
  245. Xdl_errortype *dl_ehptr = dl_defaulterror;
  246. Xdl_errortype *dl_mhptr = dl_defaultmessage;
  247. X
  248. Xvoid
  249. Xdl_seterror(eh)
  250. X    dl_errortype *eh;
  251. X{
  252. X    if ( eh == 0 )
  253. X      dl_ehptr = dl_defaulterror;
  254. X    else
  255. X      dl_ehptr = eh;
  256. X}
  257. X
  258. Xvoid
  259. Xdl_defaulterror(str)
  260. X    char *str;
  261. X{
  262. X    fprintf(stderr, "%s\n", str);
  263. X}
  264. X
  265. Xvoid
  266. Xdl_error(fmt, arg)
  267. X    char *fmt;
  268. X    int arg;
  269. X{
  270. X    char errbuf[512];
  271. X    extern int errno;
  272. X
  273. X    if ( fmt ) {
  274. X    sprintf(errbuf, fmt, arg);
  275. X    } else {
  276. X    sprintf(errbuf, "libdl: %s: %s", arg, strerror(errno));
  277. X    }
  278. X    (*dl_ehptr)(errbuf);
  279. X}
  280. X
  281. Xvoid
  282. Xdl_setmessage(eh)
  283. X    dl_errortype *eh;
  284. X{
  285. X    if ( eh == 0 )
  286. X      dl_ehptr = dl_defaultmessage;
  287. X    else
  288. X      dl_ehptr = eh;
  289. X}
  290. X
  291. Xvoid
  292. Xdl_defaultmessage(str)
  293. X    char *str;
  294. X{
  295. X    fprintf(stderr, "%s\n", str);
  296. X}
  297. X
  298. Xvoid
  299. Xdl_message(fmt, arg)
  300. X    char *fmt;
  301. X    int arg;
  302. X{
  303. X    char msgbuf[512];
  304. X
  305. X    sprintf(msgbuf, fmt, arg);
  306. X    (*dl_mhptr)(msgbuf);
  307. X}
  308. X
  309. Xvoid
  310. Xdl_nomessage(str)
  311. X    char *str;
  312. X{
  313. X}
  314. END_OF_FILE
  315. if test 2247 -ne `wc -c <'dl_error.c'`; then
  316.     echo shar: \"'dl_error.c'\" unpacked with wrong size!
  317. fi
  318. # end of 'dl_error.c'
  319. fi
  320. if test -f 'dl_findlibs.c' -a "${1}" != "-c" ; then 
  321.   echo shar: Will not clobber existing file \"'dl_findlibs.c'\"
  322. else
  323. echo shar: Extracting \"'dl_findlibs.c'\" \(1813 characters\)
  324. sed "s/^X//" >'dl_findlibs.c' <<'END_OF_FILE'
  325. X/***********************************************************
  326. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  327. XNetherlands.
  328. X
  329. X                        All Rights Reserved
  330. X
  331. XPermission to use, copy, modify, and distribute this software and its 
  332. Xdocumentation for any purpose and without fee is hereby granted, 
  333. Xprovided that the above copyright notice appear in all copies and that
  334. Xboth that copyright notice and this permission notice appear in 
  335. Xsupporting documentation, and that the names of Stichting Mathematisch
  336. XCentrum or CWI not be used in advertising or publicity pertaining to
  337. Xdistribution of the software without specific, written prior permission.
  338. X
  339. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  340. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  341. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  342. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  343. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  344. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  345. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  346. X
  347. X******************************************************************/
  348. X/*
  349. X** dl_findlibs - Find optional ld libraries for module.
  350. X*/
  351. X#include "dl.h"
  352. X
  353. Xstatic char flbuf[1030];
  354. X
  355. Xchar *
  356. Xdl_findlibs(obj)
  357. X    char *obj;
  358. X{
  359. X    int fd, n;
  360. X    
  361. X    strncpy(flbuf, obj, 1024);
  362. X    flbuf[1024] = 0;
  363. X    if ( strncmp(flbuf+strlen(flbuf)-2, ".o", 2) == 0)
  364. X      flbuf[strlen(flbuf)-2] = 0;
  365. X    strcat(flbuf, ".libs");
  366. X    if ((fd=open(flbuf, 0)) < 0 ) {
  367. X    flbuf[0] = 0;
  368. X    return flbuf;
  369. X    }
  370. X    n = read(fd, flbuf, 1024);
  371. X    close(fd);
  372. X    if ( n < 0 || n == 1024 )
  373. X      return 0;
  374. X    n--;
  375. X    if ( flbuf[n] = '\n' )
  376. X      n--;
  377. X    flbuf[n+1] = 0;
  378. X    return flbuf;
  379. X}
  380. X    
  381. END_OF_FILE
  382. if test 1813 -ne `wc -c <'dl_findlibs.c'`; then
  383.     echo shar: \"'dl_findlibs.c'\" unpacked with wrong size!
  384. fi
  385. # end of 'dl_findlibs.c'
  386. fi
  387. if test -f 'dl_getbinary.c' -a "${1}" != "-c" ; then 
  388.   echo shar: Will not clobber existing file \"'dl_getbinary.c'\"
  389. else
  390. echo shar: Extracting \"'dl_getbinary.c'\" \(2270 characters\)
  391. sed "s/^X//" >'dl_getbinary.c' <<'END_OF_FILE'
  392. X/***********************************************************
  393. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  394. XNetherlands.
  395. X
  396. X                        All Rights Reserved
  397. X
  398. XPermission to use, copy, modify, and distribute this software and its 
  399. Xdocumentation for any purpose and without fee is hereby granted, 
  400. Xprovided that the above copyright notice appear in all copies and that
  401. Xboth that copyright notice and this permission notice appear in 
  402. Xsupporting documentation, and that the names of Stichting Mathematisch
  403. XCentrum or CWI not be used in advertising or publicity pertaining to
  404. Xdistribution of the software without specific, written prior permission.
  405. X
  406. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  407. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  408. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  409. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  410. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  411. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  412. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  413. X
  414. X******************************************************************/
  415. X/*
  416. X** dl_getbinaryname - Convert program name to full pathname.
  417. X*/
  418. X#include <stdio.h>
  419. X#include <sys/types.h>
  420. X#include <sys/stat.h>
  421. X
  422. X#include "dl.h"
  423. X
  424. X#ifdef DEBUG
  425. X#define D(x) (x)
  426. X#else
  427. X#define D(x)
  428. X#endif
  429. X
  430. X/* Default path from sh(1) in Irix 4.0.1 */
  431. X#define DEF_PATH ":/usr/sbin:/usr/bsd:/bin:/usr/bin:/usr/bin/X11"
  432. X
  433. Xchar *
  434. Xdl_getbinaryname(argv0)
  435. X    char *argv0;
  436. X{
  437. X    char *p, *q;
  438. X    char *path;
  439. X    static char buf[1028];
  440. X    int i;
  441. X    struct stat st;
  442. X    char *getenv();
  443. X
  444. X    if (strchr(argv0, '/') != NULL) {
  445. X        D(printf("binary includes slash: %s\n", argv0));
  446. X        return argv0;
  447. X    }
  448. X    path = getenv("PATH");
  449. X    if (path == NULL)
  450. X        path = DEF_PATH;
  451. X    p = q = path;
  452. X    for (;;) {
  453. X        while (*q && *q != ':')
  454. X            q++;
  455. X        i = q-p;
  456. X        strncpy(buf, p, i);
  457. X        if (q > p && q[-1] != '/')
  458. X            buf[i++] = '/';
  459. X        strcpy(buf+i, argv0);
  460. X        if (stat(buf, &st) >= 0) {
  461. X            if (S_ISREG(st.st_mode) &&
  462. X                (st.st_mode & 0111)) {
  463. X                D(printf("found binary: %s\n", buf));
  464. X                return buf;
  465. X            }
  466. X        }
  467. X        if (!*q)
  468. X            break;
  469. X        p = ++q;
  470. X    }
  471. X    D(printf("can't find binary: %s\n", argv0));
  472. X    return argv0;
  473. X}
  474. END_OF_FILE
  475. if test 2270 -ne `wc -c <'dl_getbinary.c'`; then
  476.     echo shar: \"'dl_getbinary.c'\" unpacked with wrong size!
  477. fi
  478. # end of 'dl_getbinary.c'
  479. fi
  480. if test -f 'dl_loadmod.c' -a "${1}" != "-c" ; then 
  481.   echo shar: Will not clobber existing file \"'dl_loadmod.c'\"
  482. else
  483. echo shar: Extracting \"'dl_loadmod.c'\" \(4978 characters\)
  484. sed "s/^X//" >'dl_loadmod.c' <<'END_OF_FILE'
  485. X/***********************************************************
  486. XCopyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
  487. XNetherlands.
  488. X
  489. X                        All Rights Reserved
  490. X
  491. XPermission to use, copy, modify, and distribute this software and its 
  492. Xdocumentation for any purpose and without fee is hereby granted, 
  493. Xprovided that the above copyright notice appear in all copies and that
  494. Xboth that copyright notice and this permission notice appear in 
  495. Xsupporting documentation, and that the names of Stichting Mathematisch
  496. XCentrum or CWI not be used in advertising or publicity pertaining to
  497. Xdistribution of the software without specific, written prior permission.
  498. X
  499. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  500. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  501. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  502. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  503. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  504. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  505. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  506. X
  507. X******************************************************************/
  508. X/*
  509. X** An emulation of Jack's dld interface on top of GNU's dld.
  510. X** This only works if the calling program is linked with -Bstatic (or gcc)!!!
  511. X*/
  512. X
  513. X#include "dl.h"
  514. X#include "dld.h"
  515. X
  516. X#include <stdio.h>
  517. X#include <ctype.h>
  518. X#include <nlist.h>
  519. X
  520. X#define D(x)
  521. X
  522. Xstatic int inited;
  523. X
  524. Xdl_funcptr
  525. Xdl_loadmod(thisfile, loadfile, entrypoint)
  526. X    char *thisfile, *loadfile, *entrypoint;
  527. X{
  528. X    int err;
  529. X    char *libs;
  530. X    dl_funcptr func;
  531. X    
  532. X    if (!inited) {
  533. X        err = dld_init(dl_getbinaryname(thisfile));
  534. X        if (err) {
  535. X            dld_perror("Internal error");
  536. X            dl_error("dl_loadmod: dld_init of %s failed", thisfile);
  537. X            return 0;
  538. X        }
  539. X        inited = 1;
  540. X    }
  541. X
  542. X    D(fprintf(stderr, "calling dld_link(%s)\n", loadfile));
  543. X    err = dld_link(loadfile);
  544. X    if (err) {
  545. X        dld_perror("Internal error");
  546. X        dl_error("dl_loadmod: dld_link of %s failed", loadfile);
  547. X        return 0;
  548. X    }
  549. X
  550. X    libs = dl_findlibs(loadfile);
  551. X    if (libs) {
  552. X        char *p, *q;
  553. X        int i;
  554. X        char buf[1024];
  555. X        D(fprintf(stderr, "libs: '%s'\n", libs));
  556. X        p = libs;
  557. X        for (;;) {
  558. X            while (*p && isspace(*p))
  559. X                p++;
  560. X            if (!*p)
  561. X                break;
  562. X            q = p;
  563. X            while (*q && !isspace(*q))
  564. X                q++;
  565. X            i = q-p;
  566. X            strncpy(buf, p, i);
  567. X            buf[i] = '\0';
  568. X            D(fprintf(stderr, "calling dld_link(%s)\n", buf));
  569. X            err = dld_link(buf);
  570. X            if (err && err != DLD_EUNDEFSYM) {
  571. X                dld_perror("Internal error");
  572. X                dl_error("dl_loadmod: dld_link of library %s failed", buf);
  573. X            }
  574. X            p = q;
  575. X        }
  576. X    }
  577. X
  578. X    if (dld_undefined_sym_count) {
  579. X        int i;
  580. X        char **pp;
  581. X        pp = dld_list_undefined_sym();
  582. X        for (i = 0; i < dld_undefined_sym_count; i++) {
  583. X            fprintf(stderr, "\t%s\n", pp[i]);
  584. X        }
  585. X        free(pp);
  586. X        dl_error("dl_loadmod: %d undefined symbols remain",
  587. X             dld_undefined_sym_count);
  588. X        return 0;
  589. X    }
  590. X    
  591. X    if (!dld_function_executable_p(entrypoint)) {
  592. X        dl_error("dl_loadmod: function %s not executable", entrypoint);
  593. X    }
  594. X    
  595. X    D(fprintf(stderr, "call dld_get_func(%s)\n", entrypoint));
  596. X    func = (dl_funcptr) dld_get_func(entrypoint);
  597. X    if (func == 0)
  598. X        dl_error("dl_loadmod: function %s not found", entrypoint);
  599. X
  600. X    return func;
  601. X}
  602. X
  603. Xint
  604. Xdl_loadmod_mult(thisfile, loadfile, nl)
  605. X    char *thisfile, *loadfile;
  606. X    struct nlist nl[];
  607. X{
  608. X    int err, i, n;
  609. X    char *libs;
  610. X    dl_funcptr func;
  611. X    
  612. X    if (!inited) {
  613. X        err = dld_init(dl_getbinaryname(thisfile));
  614. X        if (err) {
  615. X            dld_perror("Internal error");
  616. X            dl_error("dl_loadmod_mult: dld_init of %s failed",
  617. X                 thisfile);
  618. X            return 0;
  619. X        }
  620. X        inited = 1;
  621. X    }
  622. X
  623. X    D(fprintf(stderr, "calling dld_link(%s)\n", loadfile));
  624. X    err = dld_link(loadfile);
  625. X    if (err) {
  626. X        dld_perror("Internal error");
  627. X        dl_error("dl_loadmod_mult: dld_link of %s failed", loadfile);
  628. X        return 0;
  629. X    }
  630. X
  631. X    libs = dl_findlibs(loadfile);
  632. X    if (libs) {
  633. X        char *p, *q;
  634. X        int i;
  635. X        char buf[1024];
  636. X        D(fprintf(stderr, "libs: '%s'\n", libs));
  637. X        p = libs;
  638. X        for (;;) {
  639. X            while (*p && isspace(*p))
  640. X                p++;
  641. X            if (!*p)
  642. X                break;
  643. X            q = p;
  644. X            while (*q && !isspace(*q))
  645. X                q++;
  646. X            i = q-p;
  647. X            strncpy(buf, p, i);
  648. X            buf[i] = '\0';
  649. X            D(fprintf(stderr, "calling dld_link(%s)\n", buf));
  650. X            err = dld_link(buf);
  651. X            if (err && err != DLD_EUNDEFSYM) {
  652. X                dld_perror("Internal error");
  653. X                dl_error("dl_loadmod_mult: dld_link of library %s failed", buf);
  654. X            }
  655. X            p = q;
  656. X        }
  657. X    }
  658. X
  659. X    if (dld_undefined_sym_count) {
  660. X        int i;
  661. X        char **pp;
  662. X        pp = dld_list_undefined_sym();
  663. X        for (i = 0; i < dld_undefined_sym_count; i++) {
  664. X            fprintf(stderr, "\t%s\n", pp[i]);
  665. X        }
  666. X        free(pp);
  667. X        dl_error("dl_loadmod_mult: %d undefined symbols remain",
  668. X             dld_undefined_sym_count);
  669. X        return 0;
  670. X    }
  671. X    
  672. X    for (i = n = 0; nl[i].n_name != 0; i++) {
  673. X        if (!dld_function_executable_p(nl[i].n_name)) {
  674. X            nl[i].n_value = 0;
  675. X            nl[i].n_type = 0;
  676. X            continue;
  677. X        }
  678. X        
  679. X        D(fprintf(stderr, "call dld_get_func(%s)\n", nl[i].n_name));
  680. X        nl[i].n_value = (unsigned long) dld_get_func(nl[i].n_name);
  681. X        nl[i].n_type = 1;
  682. X        n += (nl[i].n_value != 0);
  683. X    }
  684. X    return n;
  685. X}
  686. END_OF_FILE
  687. if test 4978 -ne `wc -c <'dl_loadmod.c'`; then
  688.     echo shar: \"'dl_loadmod.c'\" unpacked with wrong size!
  689. fi
  690. # end of 'dl_loadmod.c'
  691. fi
  692. if test -f 'strerror.c' -a "${1}" != "-c" ; then 
  693.   echo shar: Will not clobber existing file \"'strerror.c'\"
  694. else
  695. echo shar: Extracting \"'strerror.c'\" \(1672 characters\)
  696. sed "s/^X//" >'strerror.c' <<'END_OF_FILE'
  697. X/***********************************************************
  698. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  699. XNetherlands.
  700. X
  701. X                        All Rights Reserved
  702. X
  703. XPermission to use, copy, modify, and distribute this software and its 
  704. Xdocumentation for any purpose and without fee is hereby granted, 
  705. Xprovided that the above copyright notice appear in all copies and that
  706. Xboth that copyright notice and this permission notice appear in 
  707. Xsupporting documentation, and that the names of Stichting Mathematisch
  708. XCentrum or CWI not be used in advertising or publicity pertaining to
  709. Xdistribution of the software without specific, written prior permission.
  710. X
  711. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  712. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  713. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  714. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  715. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  716. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  717. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  718. X
  719. X******************************************************************/
  720. X
  721. X/* PD implementation of strerror() for systems that don't have it.
  722. X   Author: Guido van Rossum, CWI Amsterdam, Oct. 1990, <guido@cwi.nl>. */
  723. X
  724. X#include <stdio.h>
  725. X
  726. Xextern int sys_nerr;
  727. Xextern char *sys_errlist[];
  728. X
  729. Xchar *
  730. Xstrerror(err)
  731. X    int err;
  732. X{
  733. X    static char buf[20];
  734. X    if (err >= 0 && err < sys_nerr)
  735. X        return sys_errlist[err];
  736. X    sprintf(buf, "Unknown errno %d", err);
  737. X    return buf;
  738. X}
  739. X
  740. X#ifdef THINK_C
  741. Xint sys_nerr = 0;
  742. Xchar *sys_errlist[1] = 0;
  743. X#endif
  744. END_OF_FILE
  745. if test 1672 -ne `wc -c <'strerror.c'`; then
  746.     echo shar: \"'strerror.c'\" unpacked with wrong size!
  747. fi
  748. # end of 'strerror.c'
  749. fi
  750. if test ! -d 'test' ; then
  751.     echo shar: Creating directory \"'test'\"
  752.     mkdir 'test'
  753. fi
  754. if test -f 'test/Makefile' -a "${1}" != "-c" ; then 
  755.   echo shar: Will not clobber existing file \"'test/Makefile'\"
  756. else
  757. echo shar: Extracting \"'test/Makefile'\" \(508 characters\)
  758. sed "s/^X//" >'test/Makefile' <<'END_OF_FILE'
  759. X# You may have to change this definition of where dld is...
  760. XDLD=    ../../dld-3.2.3
  761. XDL=    ..
  762. XCFLAGS=    -g -I$(DL)
  763. XLIBS=    $(DL)/libdl.a $(DLD)/libdld.a
  764. XCC=    gcc
  765. X
  766. Xtest: test.o $(LIBS) sub.o sub2.o
  767. X    $(CC) test.o $(LIBS) -o test
  768. X
  769. Xsub.o: sub.c
  770. X    $(CC) -c sub.c -o sub.o
  771. X
  772. Xsub2.o: sub2.c
  773. X    $(CC) -c sub2.c -o sub2.o
  774. X
  775. X$(DL)/libdl.a::
  776. X    (cd $(DL); make)
  777. X
  778. X$(DLD)/libdld.a::
  779. X    (cd $(DLD); make)
  780. X
  781. Xclean::
  782. X        -rm -f *.o core [,#@]* *~ *.orig *.old *.bak *.BAK \
  783. X            nohup.out Part?? *.ld
  784. X
  785. Xclobber::    clean
  786. X        -rm -f lib*.a tags TAGS test
  787. END_OF_FILE
  788. if test 508 -ne `wc -c <'test/Makefile'`; then
  789.     echo shar: \"'test/Makefile'\" unpacked with wrong size!
  790. fi
  791. # end of 'test/Makefile'
  792. fi
  793. if test -f 'test/sub.c' -a "${1}" != "-c" ; then 
  794.   echo shar: Will not clobber existing file \"'test/sub.c'\"
  795. else
  796. echo shar: Extracting \"'test/sub.c'\" \(308 characters\)
  797. sed "s/^X//" >'test/sub.c' <<'END_OF_FILE'
  798. X
  799. Xint i;
  800. Xint j = 2;
  801. X
  802. Xsub1() {
  803. X    printf("sub1: called %f\n", 0.123);
  804. X}
  805. X
  806. Xsub2() {
  807. X    printf("sub2: calling mainsub\n");
  808. X    submain();
  809. X    printf("sub2: returngin\n");
  810. X}
  811. X
  812. Xsub3() {
  813. X    double sin();
  814. X    
  815. X    printf("Sub3: called. Attempt sin(3.1415):\n");
  816. X    printf("sin(%f) = %f\n", 3.1415, sin(3.1415));
  817. X}
  818. END_OF_FILE
  819. if test 308 -ne `wc -c <'test/sub.c'`; then
  820.     echo shar: \"'test/sub.c'\" unpacked with wrong size!
  821. fi
  822. # end of 'test/sub.c'
  823. fi
  824. if test -f 'test/sub.libs' -a "${1}" != "-c" ; then 
  825.   echo shar: Will not clobber existing file \"'test/sub.libs'\"
  826. else
  827. echo shar: Extracting \"'test/sub.libs'\" \(32 characters\)
  828. sed "s/^X//" >'test/sub.libs' <<'END_OF_FILE'
  829. X/usr/lib/libm.a /usr/lib/libc.a
  830. END_OF_FILE
  831. if test 32 -ne `wc -c <'test/sub.libs'`; then
  832.     echo shar: \"'test/sub.libs'\" unpacked with wrong size!
  833. fi
  834. # end of 'test/sub.libs'
  835. fi
  836. if test -f 'test/sub2.c' -a "${1}" != "-c" ; then 
  837.   echo shar: Will not clobber existing file \"'test/sub2.c'\"
  838. else
  839. echo shar: Extracting \"'test/sub2.c'\" \(185 characters\)
  840. sed "s/^X//" >'test/sub2.c' <<'END_OF_FILE'
  841. X
  842. Xint i;
  843. Xint j = 2;
  844. X
  845. Xsub1() {
  846. X    printf("sub2-sub1: called %f\n", 0.456);
  847. X}
  848. X
  849. Xsub2() {
  850. X    printf("sub2-sub2: calling mainsub\n");
  851. X    submain();
  852. X    printf("sub2-sub2: returning\n");
  853. X}
  854. END_OF_FILE
  855. if test 185 -ne `wc -c <'test/sub2.c'`; then
  856.     echo shar: \"'test/sub2.c'\" unpacked with wrong size!
  857. fi
  858. # end of 'test/sub2.c'
  859. fi
  860. if test -f 'test/test.c' -a "${1}" != "-c" ; then 
  861.   echo shar: Will not clobber existing file \"'test/test.c'\"
  862. else
  863. echo shar: Extracting \"'test/test.c'\" \(721 characters\)
  864. sed "s/^X//" >'test/test.c' <<'END_OF_FILE'
  865. X/*
  866. X** Test.c - Test shared library
  867. X*/
  868. X#include <stdio.h>
  869. X
  870. X#include "dl.h"
  871. X
  872. Xmain(argc, argv)
  873. X    int argc;
  874. X    char **argv;
  875. X{
  876. X    dl_funcptr sub1, sub2;
  877. X    
  878. X    printf("main: load function %s from %s\n", argv[2], argv[1]);
  879. X    sub1 = dl_loadmod(argv[0], argv[1], argv[2]);
  880. X    if ( sub1 == 0 ) {
  881. X    exit(1);
  882. X    }
  883. X    if ( argc >= 5 ) {
  884. X     printf("main: load function %s from %s\n", argv[4], argv[3]);
  885. X     sub2 = dl_loadmod(argv[0], argv[3], argv[4]);
  886. X     if ( sub2 == 0 ) {
  887. X         exit(1);
  888. X         }
  889. X    }
  890. X    printf("main: calling %s\n", argv[2]);
  891. X    (*sub1)();
  892. X    if ( argc == 5 ) {
  893. X    printf("main: calling %s\n", argv[4]);
  894. X    (*sub2)();
  895. X    }
  896. X    printf("main: all done\n");
  897. X}
  898. X
  899. Xsubmain() {
  900. X    printf("submain: called\n");
  901. X}
  902. END_OF_FILE
  903. if test 721 -ne `wc -c <'test/test.c'`; then
  904.     echo shar: \"'test/test.c'\" unpacked with wrong size!
  905. fi
  906. # end of 'test/test.c'
  907. fi
  908. echo shar: End of archive 1 \(of 1\).
  909. cp /dev/null ark1isdone
  910. MISSING=""
  911. for I in 1 ; do
  912.     if test ! -f ark${I}isdone ; then
  913.     MISSING="${MISSING} ${I}"
  914.     fi
  915. done
  916. if test "${MISSING}" = "" ; then
  917.     echo You have the archive.
  918.     rm -f ark[1-9]isdone
  919. else
  920.     echo You still need to unpack the following archives:
  921.     echo "        " ${MISSING}
  922. fi
  923. ##  End of shell archive.
  924. exit 0
  925.