"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* Copyright (C) 2000-2002 Ghostgum Software Pty Ltd. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under licence and may not be copied,
7 modified or distributed except as expressly authorised under the terms
8 of the licence contained in the file LICENCE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostgum.com.au/ or contact Ghostsgum Software Pty Ltd,
12 218 Gallaghers Rd, Glen Waverley VIC 3150, AUSTRALIA,
13 Fax +61 3 9886 6616.
14 */
15
16 /* $Id: xdll.c,v 1.3 2003/05/06 13:17:40 ghostgum Exp $ */
17 /* Unix shared object loading using dlopen */
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <dlfcn.h>
22 #include "common.h"
23 #include "cdll.h"
24
25 /******************************************************************/
26
27 static int
28 dll_msg(TCHAR *msg, LPCTSTR str, int msglen)
29 {
30 int len = (int)cslen(str);
31 if (len < msglen){
32 csncat(msg, str, len);
33 msglen -= len;
34 }
35 return msglen;
36 }
37
38
39
40 /* platform dependent */
41 /* Load Ghostscript DLL */
42 int
43 dll_open(GGMODULE *hmodule, LPCTSTR name, TCHAR *msg, int msglen)
44 {
45 char *shortname;
46 char *s;
47 TCHAR buf[MAXSTR];
48
49
50 memset(msg, 0, msglen);
51 msglen = dll_msg(msg, TEXT("Trying to load "), msglen);
52 msglen = dll_msg(msg, name, msglen);
53 msglen = dll_msg(msg, TEXT("\n"), msglen);
54
55 /* Try to load DLL first with given path */
56 *hmodule = dlopen(name, RTLD_NOW);
57 if (*hmodule == NULL) {
58 /* failed */
59 msglen = dll_msg(msg, TEXT(" Failed, "), msglen);
60 msglen = dll_msg(msg, dlerror(), msglen);
61 msglen = dll_msg(msg, TEXT("\n"), msglen);
62 /* try once more, this time on system search path */
63 memset(buf, 0, sizeof(buf));
64 strncpy(buf, name, sizeof(buf)-1);
65 s = shortname = buf;
66 while (*s) {
67 if (*s == '/')
68 shortname = s+1;
69 s = CHARNEXT(s);
70 }
71 msglen = dll_msg(msg, TEXT("Trying to load "), msglen);
72 msglen = dll_msg(msg, shortname, msglen);
73 msglen = dll_msg(msg, TEXT("\n"), msglen);
74 *hmodule = dlopen(shortname, RTLD_NOW);
75 if (*hmodule == NULL) {
76 /* failed again */
77 msglen = dll_msg(msg, TEXT(" Failed, "), msglen);
78 msglen = dll_msg(msg, dlerror(), msglen);
79 msglen = dll_msg(msg, TEXT("\n"), msglen);
80 }
81 }
82 return 0;
83 }
84
85 /* Unload Ghostscript DLL */
86 int
87 dll_close(GGMODULE *hmodule)
88 {
89 dlclose(*hmodule);
90 return 0;
91 }
92
93 dll_proc
94 dll_sym(GGMODULE *hmodule, const char *name)
95 {
96 return (dll_proc)dlsym(*hmodule, name);
97 }
98
99
100
101 /******************************************************************/