1a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat/**
2a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     dlopen(), dlclose() dlsym(), dlerror() emulation for OS/400.
3a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***
4a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     See Copyright for the status of this software.
5a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***
6a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
7a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat**/
8a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
9a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <stdarg.h>
10a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <stdio.h>
11a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <ctype.h>
12a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <errno.h>
13a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <stdlib.h>
14a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <unistd.h>
15a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <string.h>
16a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <dirent.h>
17a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <pthread.h>
18a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
19a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <sys/types.h>
20a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <sys/stat.h>
21a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
22a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <except.h>             /* AS400 exceptions. */
23a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <miptrnam.h>           /* MI pointers support. */
24a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <qusec.h>              /* Error structures. */
25a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <qp0lstdi.h>           /* Path to QSYS object name. */
26a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <qp0z1170.h>           /* For Qp0zInitEnv(). */
27a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <qleawi.h>             /* For QleActBndPgmLong() definitions. */
28a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <qsy.h>                /* Qualified name structure. */
29a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <qmhrtvm.h>            /* Retrieve message from message file. */
30a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
31a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <mih/rinzstat.h>
32a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include <mih/matactex.h>
33a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
34a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include "libxml/hash.h"
35a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#include "dlfcn.h"
36a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
37a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
38a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat/**
39a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     Maximum internal path length.
40a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat**/
41a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
42a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#define MAXPATHLEN              5120
43a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
44a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
45a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat/**
46a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     Maximum error string length.
47a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat**/
48a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
49a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#define MAX_ERR_STR             511
50a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
51a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
52a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat/**
53a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     Field address macro.
54a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat**/
55a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
56a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#define offset_by(t, b, o)      ((t *) ((char *) (b) + (unsigned int) (o)))
57a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
58a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
59a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat/**
60a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     Global flags.
61a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat**/
62a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
63a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#define INITED          000001          /* Package has been initialized. */
64a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#define THREADS         000002          /* Multithreaded job. */
65a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#define MULTIBUF        000004          /* One error buffer per thread. */
66a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
67a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
68a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat/**
69a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     DLL handle private structure.
70a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat**/
71a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
72a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerattypedef struct {
73a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qle_ABP_Info_Long_t     actinfo;        /* Activation information. */
74a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        _SYSPTR                 pointer;        /* Pointer to DLL object. */
75a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        unsigned int            actcount;       /* Activation count. */
76a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}               dlinfo;
77a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
78a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
79a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat/**
80a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat***     Per-thread structure.
81a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat**/
82a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
83a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerattypedef struct {
84a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        unsigned int    lockcount;              /* Mutex lock count. */
85a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        unsigned int    iserror;                /* Flag error present. */
86a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char            str[MAX_ERR_STR + 1];   /* Error string buffer. */
87a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}               dlts_t;
88a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
89a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
90a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic pthread_mutex_t  dlmutex = PTHREAD_MUTEX_INITIALIZER;
91a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic xmlHashTablePtr  dldir = (xmlHashTablePtr) NULL; /* DLL directory. */
92a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic unsigned int     dlflags = 0;                    /* Package flags. */
93a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic pthread_key_t    dlkey;
94a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic dlts_t           static_buf;             /* Static error buffer. */
95a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
96a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
97a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
98a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
99a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlthreadterm(void * mem)
100a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
101a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
102a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        free(mem);
103a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        pthread_setspecific(dlkey, NULL);
104a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
105a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
106a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
107a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
108a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlterm(void)
109a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
110a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
111a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        void * p;
112a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
113a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlflags & MULTIBUF) {
114a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = pthread_getspecific(dlkey);
115a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
116a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (p)
117a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        dlthreadterm(p);
118a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
119a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
120a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlflags & THREADS)
121a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                pthread_mutex_lock(&dlmutex);
122a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
123a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dldir) {
124a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                xmlHashFree(dldir, (xmlHashDeallocator) NULL);
125a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dldir = NULL;
126a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
127a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
128a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlflags & MULTIBUF)
129a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                pthread_key_delete(dlkey);
130a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
131a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlflags |= ~(INITED | MULTIBUF);
132a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        pthread_mutex_unlock(&dlmutex);
133a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        pthread_mutex_destroy(&dlmutex);
134a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
135a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
136a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
137a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
138a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlinit(void)
139a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
140a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
141a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int locked;
142a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
143a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
144a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Initialize the package.
145a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Should be call once per process.
146a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
147a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
148a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        locked = !pthread_mutex_lock(&dlmutex);
149a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
150a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlflags & INITED)) {
151a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlflags &= ~THREADS;
152a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
153a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (locked)
154a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        dlflags |= THREADS;
155a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
156a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                Qp0zInitEnv();
157a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dldir = xmlHashCreate(16);
158a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlflags &= ~MULTIBUF;
159a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
160a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (dlflags & THREADS)
161a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (!pthread_key_create(&dlkey, dlthreadterm))
162a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                dlflags |= MULTIBUF;
163a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
164a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                atexit(dlterm);
165a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlflags |= INITED;
166a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
167a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
168a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (locked)
169a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                pthread_mutex_unlock(&dlmutex);
170a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
171a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
172a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
173a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
174a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlthreadinit(void)
175a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
176a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
177a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlts_t * p;
178a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
179a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlflags & INITED))
180a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlinit();
181a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
182a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlflags & MULTIBUF) {
183a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = pthread_getspecific(dlkey);
184a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
185a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (!p) {
186a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        p = (dlts_t *) malloc(sizeof *p);
187a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
188a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (p) {
189a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                p->lockcount = 0;
190a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                p->iserror = 0;
191a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
192a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                if (pthread_setspecific(dlkey, p))
193a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                        free(p);
194a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                }
195a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
196a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
197a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
198a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
199a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
200a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
201a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdllock(void)
202a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
203a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
204a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlts_t * p;
205a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
206a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlflags & THREADS))
207a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return;
208a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
209a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlflags & MULTIBUF) {
210a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = pthread_getspecific(dlkey);
211a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
212a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (p && p->lockcount) {
213a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        p->lockcount++;
214a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return;
215a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
216a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
217a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else
218a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = (dlts_t *) NULL;
219a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
220a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (pthread_mutex_lock(&dlmutex))
221a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return;
222a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
223a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (p)
224a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p->lockcount++;
225a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
226a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
227a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
228a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
229a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlunlock(void)
230a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
231a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
232a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlts_t * p;
233a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
234a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlflags & THREADS))
235a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return;
236a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
237a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlflags & MULTIBUF) {
238a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = pthread_getspecific(dlkey);
239a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
240a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (p && p->lockcount > 1) {
241a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        p->lockcount--;
242a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return;
243a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
244a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
245a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else
246a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = (dlts_t *) NULL;
247a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
248a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (pthread_mutex_unlock(&dlmutex))
249a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return;
250a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
251a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (p)
252a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p->lockcount--;
253a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
254a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
255a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
256a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratconst char *
257a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlerror(void)
258a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
259a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
260a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlts_t * p;
261a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
262a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlthreadinit();
263a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
264a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlflags & MULTIBUF))
265a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = &static_buf;
266a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!(p = (dlts_t *) pthread_getspecific(dlkey)))
267a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = &static_buf;
268a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
269a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!p->iserror)
270a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return (const char *) NULL;
271a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
272a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        p->iserror = 0;
273a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return p->str;
274a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
275a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
276a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
277a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
278a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlseterror_from_errno(unsigned int err_no)
279a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
280a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
281a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlts_t * p;
282a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
283a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlflags & MULTIBUF))
284a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = &static_buf;
285a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!(p = (dlts_t *) pthread_getspecific(dlkey)))
286a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                p = &static_buf;
287a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
288a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(p->str, strerror(err_no));
289a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        p->iserror = 1;
290a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
291a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
292a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
293a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void
294a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlseterror_from_exception(volatile _INTRPT_Hndlr_Parms_T * excp)
295a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
296a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
297a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int i;
298a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qmh_Rtvm_RTVM0300_t * imp;
299a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char * cp;
300a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        _INTRPT_Hndlr_Parms_T * p;
301a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlts_t * q;
302a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char rtvmbuf[30000];
303a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qus_EC_t errinfo;
304a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
305a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        p = (_INTRPT_Hndlr_Parms_T *) excp;
306a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        errinfo.Bytes_Provided = 0;             /* Exception on error. */
307a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        QMHRTVM(rtvmbuf, sizeof rtvmbuf, "RTVM0300", p->Msg_Id,
308a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            "QCPFMSG   QSYS      ", p->Ex_Data, p->Msg_Data_Len,
309a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            "*YES      ", "*NO       ", &errinfo);
310a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        imp = offset_by(Qmh_Rtvm_RTVM0300_t, rtvmbuf, 0);
311a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
312a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlflags & MULTIBUF))
313a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                q = &static_buf;
314a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!(q = (dlts_t *) pthread_getspecific(dlkey)))
315a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                q = &static_buf;
316a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
317a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (i = imp->Length_Message_Returned)
318a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                cp = offset_by(char, imp, imp->Offset_Message_Returned);
319a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (i = imp->Length_Help_Returned)
320a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                cp = offset_by(char, imp, imp->Offset_Help_Returned);
321a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else {
322a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                q->iserror = 0;
323a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return;
324a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
325a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
326a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        q->iserror = 1;
327a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
328a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (i > sizeof q->str - 1)
329a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                i = sizeof q->str - 1;
330a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
331a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        memcpy(q->str, cp, i);
332a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        q->str[i] = '\0';
333a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
334a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
335a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
336a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
337a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlparentpath(const char * path, size_t len)
338a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
339a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
340a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (len <= 1)
341a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return len;
342a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
343a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        while (path[--len] != '/')
344a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                ;
345a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
346a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return len? len: 1;
347a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
348a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
349a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
350a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
351a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlmakepath(char * path, size_t pathlen, const char * tail, size_t taillen)
352a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
353a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
354a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int i;
355a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
356a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (taillen && tail[0] == '/')
357a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                pathlen = 0;
358a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
359a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (;;) {
360a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                while (taillen && *tail == '/') {
361a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        tail++;
362a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        taillen--;
363a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
364a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
365a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (!taillen)
366a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        break;
367a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
368a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                for (i = 0; i < taillen; i++)
369a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (tail[i] == '/')
370a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                break;
371a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
372a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (*tail == '.')
373a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        switch (i) {
374a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
375a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        case 2:
376a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                if (tail[1] != '.')
377a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                        break;
378a136fc2e5a8893a02b0912862d26a575fcbd641aXin Li
379a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                pathlen = dlparentpath(path, pathlen);
380a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
381a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        case 1:
382a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                tail += i;
383a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                taillen -= i;
384a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                continue;
385a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                }
386a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
387a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (pathlen + i + 1 >= MAXPATHLEN) {
388a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        errno = ENAMETOOLONG;
389a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
390a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
391a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
392a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                path[pathlen++] = '/';
393a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                memcpy(path + pathlen, tail, i);
394a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                pathlen += i;
395a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
396a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
397a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!pathlen)
398a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                path[pathlen++] = '/';
399a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
400a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        path[pathlen] = '\0';
401a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return pathlen;
402a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
403a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
404a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
405a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
406a6c5b022f1d515f20beb01b70466893b64e33325Patrick MonneratdlresolveLink(const char * path, char * buf, size_t bufsiz)
407a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
408a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
409a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int n;
410a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int l1;
411a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int l2;
412a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        struct stat sbuf;
413a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char buf1[MAXPATHLEN + 1];
414a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char buf2[MAXPATHLEN + 1];
415a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
416a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
417a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Resolve symbolic link to IFS object name.
418a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
419a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
420a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!buf) {
421a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = EFAULT;
422a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
423a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
424a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
425a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!path || !*path || !bufsiz) {
426a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = EINVAL;
427a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
428a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
429a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
430a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (*path != '/') {
431a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (!getcwd(buf1, sizeof buf1))
432a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
433a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
434a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                l1 = strlen(buf1);
435a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
436a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else
437a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                l1 = 0;
438a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
439a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        l1 = dlmakepath(buf1, l1, path, strlen(path));
440a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        n = 0;
441a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
442a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (;;) {
443a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (l1 < 0)
444a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
445a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
446a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (n++ >= 256) {
447a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        errno = ELOOP;
448a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
449a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
450a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
451a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (lstat(buf1, &sbuf)) {
452a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (errno == ENOENT)
453a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                break;
454a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
455a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
456a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
457a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
458a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (!S_ISLNK(sbuf.st_mode))
459a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        break;
460a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
461a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (sbuf.st_size > MAXPATHLEN) {
462a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        errno = ENAMETOOLONG;
463a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
464a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
465a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
466a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                l2 = readlink(buf1, buf2, MAXPATHLEN + 1);
467a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
468a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (l2 < 0)
469a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
470a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
471a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (buf2[0] != '/')
472a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        l1 = dlparentpath(buf1, l1);
473a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
474a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                l1 = dlmakepath(buf1, l1, buf2, l2);
475a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
476a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
477a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (l1 >= bufsiz) {
478a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = ENAMETOOLONG;
479a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
480a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
481a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
482a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        memcpy(buf, buf1, l1 + 1);
483a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return l1;
484a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
485a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
486a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
487a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
488a6c5b022f1d515f20beb01b70466893b64e33325Patrick MonneratdlGetObjectName(Qp0l_QSYS_Info_t * qsysinfo, const char * dir,
489a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        int dirlen, const char * link)
490a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
491a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
492a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int n;
493a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char * namebuf;
494a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qlg_Path_Name_T * qptp;
495a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char pathbuf[sizeof(Qlg_Path_Name_T) + _QP0L_DIR_NAME_LG + 4];
496a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qus_EC_t errinfo;
497a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        struct stat sbuf;
498a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
499a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
500a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Get QSYS object library/name/member and type corresponding to
501a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             the symbolic `link' in directory `dir'.
502a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
503a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
504a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!qsysinfo) {
505a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = EFAULT;
506a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
507a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
508a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
509a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!dir && !link) {
510a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = EINVAL;
511a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
512a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
513a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
514a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        qptp = (Qlg_Path_Name_T *) pathbuf;
515a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        namebuf = pathbuf + sizeof(Qlg_Path_Name_T);
516a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        n = 0;
517a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
518a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
519a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Build full path.
520a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
521a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
522a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dir) {
523a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (dirlen < 0 || dirlen > _QP0L_DIR_NAME_LG + 4)
524a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        dirlen = _QP0L_DIR_NAME_LG + 4;
525a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
526a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                while (*dir && n < dirlen)
527a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        namebuf[n++] = *dir++;
528a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
529a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
530a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (n && namebuf[n - 1] == '/')
531a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                n--;
532a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
533a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (link) {
534a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (*link && *link != '/' && n < _QP0L_DIR_NAME_LG + 4)
535a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        namebuf[n++] = '/';
536a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
537a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                while (*link && n < _QP0L_DIR_NAME_LG + 4)
538a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        namebuf[n++] = *link++;
539a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
540a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
541a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!n || n > _QP0L_DIR_NAME_LG) {
542a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = ENAMETOOLONG;
543a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
544a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
545a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
546a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        namebuf[n] = '\0';
547a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        n = dlresolveLink(namebuf, namebuf, _QP0L_DIR_NAME_LG + 1);
548a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
549a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (n == -1)
550a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
551a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
552a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (stat(namebuf, &sbuf))
553a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
554a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
555a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        memset((char *) qptp, 0, sizeof *qptp);
556a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        qptp->Path_Length = n;
557a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        qptp->Path_Name_Delimiter[0] = '/';
558a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        errinfo.Bytes_Provided = sizeof errinfo;
559a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qp0lCvtPathToQSYSObjName(qptp, qsysinfo, "QSYS0100", sizeof *qsysinfo,
560a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            0, &errinfo);
561a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return errinfo.Bytes_Available? -1: 0;
562a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
563a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
564a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
565a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic const char *
566a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratgetcomponent(char * dst, const char * src)
567a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
568a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
569a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int i;
570a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
571a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
572a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Get a path component of at most 10 characters and
573a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             map it to upper case.
574a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Return the address of the next delimiter in source.
575a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
576a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
577a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (i = 0;; src++) {
578a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (!*src || *src == ' ' || *src == '/') {
579a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        *dst = '\0';
580a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return src;
581a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
582a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
583a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (i < 10) {
584a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        *dst++ = toupper(*src);
585a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        i++;
586a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
587a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
588a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
589a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
590a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
591a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
592a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlpath2QSYS(Qp0l_QSYS_Info_t * qsysinfo, const char * path, const char * dftlib)
593a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
594a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
595a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        unsigned int flags;
596a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char * cp;
597a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
598a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
599a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Convert the given path to a QSYS object name.
600a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Syntax rules for paths are:
601a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***
602a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     '/'+ [ <library> [  '/'+ <file> [ '/'+ <member> ] ] '/'* ]
603a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     <library> '/'+ <file> [ '/'+ <member> ] '/'*
604a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     <file> '/'*
605a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***
606a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     If default library is not given, *LIBL is assumed.
607a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Components may no contain spaces. They are translated to
608a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             uppercase. Only the first 10 characters are significant.
609a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     There is no check for the validity of the given components and
610a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             for the object existence.
611a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Component types are not in the path, but generated internally.
612a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     CCSID is not processed.
613a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***
614a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Return 0 upon success, else -1.
615a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
616a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
617a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!qsysinfo || !path) {
618a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = EFAULT;
619a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
620a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
621a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
622a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
623a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Strip leading spaces.
624a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
625a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
626a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        while (*path == ' ')
627a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                path++;
628a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
629a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
630a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Check for null path.
631a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
632a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
633a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!*path) {
634a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = EINVAL;
635a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
636a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
637a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
638a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
639a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Preset the result structure.
640a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
641a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
642a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        memset((char *) qsysinfo, 0, sizeof *qsysinfo);
643a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
644a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
645a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Determine the format.
646a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
647a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
648a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (*path == '/') {
649a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                /**
650a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                ***     Library component present.
651a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                **/
652a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
653a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                while (*++path == '/')
654a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        ;
655a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
656a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (!*path || *path == ' ')
657a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        strcpy(qsysinfo->Lib_Name, "QSYS");
658a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                else
659a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        path = getcomponent(qsysinfo->Lib_Name, path);
660a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
661a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                /**
662a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                ***     Check for file component and get it.
663a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                **/
664a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
665a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (*path == '/') {
666a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        while (*++path == '/')
667a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                ;
668a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
669a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (*path && *path != ' ')
670a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                path = getcomponent(qsysinfo->Obj_Name, path);
671a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
672a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
673a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else {
674a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                /**
675a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                ***     The mandatory component is the <file>.
676a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                **/
677a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
678a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                path = getcomponent(qsysinfo->Obj_Name, path);
679a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
680a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                while (*path == '/')
681a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        path++;
682a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
683a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                /**
684a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                ***     If there is a second component, move the first to
685a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                ***             the library name and parse the file name.
686a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                **/
687a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
688a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (*path && *path != ' ') {
689a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        strcpy(qsysinfo->Lib_Name, qsysinfo->Obj_Name);
690a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        memset(qsysinfo->Obj_Name, 0,
691a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                            sizeof qsysinfo->Obj_Name);
692a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        path = getcomponent(qsysinfo->Obj_Name, path);
693a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
694a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                else
695a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        strcpy(qsysinfo->Lib_Name, dftlib? dftlib: "*LIBL");
696a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
697a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
698a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
699a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Check and set-up member.
700a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
701a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
702a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        while (*path == '/')
703a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                path++;
704a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
705a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (*path && *path != ' ') {
706a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                path = getcomponent(qsysinfo->Mbr_Name, path);
707a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                strcpy(qsysinfo->Mbr_Type, "*MBR");
708a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
709a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                while (*path == '/')
710a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        path++;
711a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
712a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
713a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(qsysinfo->Lib_Type, "*LIB");
714a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
715a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (qsysinfo->Obj_Name[0])
716a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                strcpy(qsysinfo->Obj_Type, "*FILE");
717a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
718a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        qsysinfo->Bytes_Returned = sizeof *qsysinfo;
719a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        qsysinfo->Bytes_Available = sizeof *qsysinfo;
720a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
721a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
722a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Strip trailing spaces.
723a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
724a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
725a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        while (*path == ' ')
726a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                path++;
727a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
728a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (*path) {
729a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = EINVAL;
730a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
731a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
732a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
733a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return 0;
734a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
735a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
736a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
737a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
738a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdl_ifs_link(Qp0l_QSYS_Info_t * qsysinfo, const char * pathname)
739a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
740a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
741a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
742a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     If `pathname' is a link found in IFS, set `qsysinfo' to its
743a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             DB2 name.
744a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Return 0 if OK, else -1.
745a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
746a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
747a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return dlGetObjectName(qsysinfo, (const char *) NULL, 0, pathname);
748a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
749a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
750a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
751a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
752a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdl_path_link(Qp0l_QSYS_Info_t * qsysinfo, const char * pathvar,
753a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        const char * filename, int (* testproc)(const Qp0l_QSYS_Info_t *))
754a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
755a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
756a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        const char * p;
757a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        const char * q;
758a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        unsigned int i;
759a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        const char * path;
760a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
761a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
762a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     If `filename' is not a path and is a link found in one of the
763a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             colon-separated paths in environment variable `pathvar',
764a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             set `qsysinfo' to its DB2 name.
765a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Return 0 if OK, else -1.
766a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
767a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
768a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        i = _QP0L_DIR_NAME_LG;
769a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
770a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (p = filename; *p; p++)
771a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (*p == '/' || !--i)
772a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;              /* Too long or a path. */
773a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
774a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
775a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Make sure we have the LD_LIBRARY_PATH environment
776a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             variable value.
777a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
778a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
779a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        path = getenv(pathvar);
780a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
781a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!path)
782a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;                      /* No path list. */
783a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
784a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
785a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Try in each path listed.
786a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
787a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
788a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        q = path;
789a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
790a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!*q)
791a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;                      /* No path list. */
792a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
793a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (;;) {
794a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                for (p = q; *p && *p != ':'; p++)
795a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        ;
796a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
797a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (p > q)                      /* Ignore null path. */
798a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (!dlGetObjectName(qsysinfo, q, p - q, filename))
799a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                if (!testproc || (*testproc)(qsysinfo))
800a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                        return 0;       /* Found: return. */
801a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
802a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (!*p)
803a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        break;
804a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
805a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                q = p + 1;
806a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
807a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
808a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        errno = ENOENT;
809a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return -1;
810a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
811a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
812a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
813a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
814a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdl_DB2_path(Qp0l_QSYS_Info_t * qsysinfo, const char * pathname)
815a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
816a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
817a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlpath2QSYS(qsysinfo, pathname, (const char *) NULL))
818a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
819a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
820a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (qsysinfo->Mbr_Type[0])
821a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;      /* Service program may not have members. */
822a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
823a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!qsysinfo->Obj_Type[0])
824a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;      /* Object must be specified. */
825a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
826a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(qsysinfo->Obj_Type, "*SRVPGM");  /* Set our object type. */
827a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return 0;
828a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
829a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
830a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
831a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
832a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdl_DB2_name(char * dst, const char * name)
833a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
834a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
835a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int i;
836a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
837a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (i = 0; i < 10; i++) {
838a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                switch (*name) {
839a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
840a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                default:
841a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (!islower(*name))
842a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                break;
843a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
844a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                case '\0':
845a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                case '/':
846a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                case ' ':
847a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
848a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
849a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
850a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                *dst++ = *name++;
851a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
852a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
853a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!i)
854a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
855a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
856a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        *dst = '\0';
857a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return 0;
858a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
859a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
860a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
861a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
862a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdl_qualified_object(Qp0l_QSYS_Info_t * qsysinfo, const char * pathname)
863a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
864a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
865a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        memset((char *) qsysinfo, 0, sizeof *qsysinfo);
866a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
867a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dl_DB2_name(qsysinfo->Obj_Name, pathname) ||
868a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            dl_DB2_name(qsysinfo->Lib_Name, pathname + 10))
869a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
870a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
871a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(qsysinfo->Lib_Type, "*LIB");
872a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(qsysinfo->Obj_Type, "*SRVPGM");
873a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return 0;
874a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
875a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
876a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
877a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
878a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdl_lib_object(Qp0l_QSYS_Info_t * qsysinfo,
879a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                const char * libname, const char * pathname)
880a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
881a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
882a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int i;
883a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char * cp;
884a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
885a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(qsysinfo->Lib_Name, libname);
886a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(qsysinfo->Lib_Type, "*LIB");
887a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        strcpy(qsysinfo->Obj_Type, "*SRVPGM");
888a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        cp = qsysinfo->Obj_Name;
889a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
890a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        while (*pathname == ' ')
891a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                pathname++;
892a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
893a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (i = 0;; pathname++) {
894a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                switch (*pathname) {
895a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
896a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                case '\0':
897a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                case ' ':
898a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        break;
899a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
900a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                case '/':
901a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return -1;
902a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
903a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                default:
904a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        if (i < 10)
905a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                                *cp++ = toupper(*pathname);
906a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
907a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        i++;
908a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        continue;
909a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        }
910a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
911a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                break;
912a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
913a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
914a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        while (*pathname == ' ')
915a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                pathname++;
916a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
917a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!i || *pathname)
918a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
919a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
920a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        *cp = '\0';
921a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return 0;
922a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
923a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
924a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
925a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
926a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdl_is_srvpgm(const Qp0l_QSYS_Info_t * qsysinfo)
927a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
928a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
929a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        struct stat sbuf;
930a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char namebuf[100];
931a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
932a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!qsysinfo->Lib_Name[0] || strcmp(qsysinfo->Lib_Type, "*LIB") ||
933a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            !qsysinfo->Obj_Name[0] || strcmp(qsysinfo->Obj_Type, "*SRVPGM") ||
934a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            qsysinfo->Mbr_Name[0] || qsysinfo->Mbr_Type[0])
935a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return 0;
936a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
937a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
938a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Build the IFS path name for the DB2 object.
939a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
940a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
941a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        sprintf(namebuf, "%s/%s.LIB/%s.SRVPGM",
942a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            strcmp(qsysinfo->Lib_Name, "QSYS")? "/QSYS.LIB": "",
943a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            qsysinfo->Lib_Name, qsysinfo->Obj_Name);
944a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
945a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return stat(namebuf, &sbuf) == 0;
946a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
947a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
948a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
949a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic int
950a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlreinit(dlinfo * dlip)
951a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
952a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
953a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        RINZ_TEMPL_T t;
954a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        RINZ_TEMPL_T * p;
955a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        volatile _INTRPT_Hndlr_Parms_T excbuf;
956a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
957a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlip->actinfo.Flags & QLE_ABP_WAS_ACTIVE)
958a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return 0;
959a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
960a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
961a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Attempt to reinitialize the service program that was loaded.
962a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     The service program must be created to allow re-initialization:
963a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             ALWRINZ(*YES) for this to work. The default is
964a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             ALWRINZ(*NO).
965a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
966a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
967a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma exception_handler(err, excbuf, 0, _C2_MH_ESCAPE, _CTLA_HANDLE_NO_MSG)
968a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        p = &t;
969a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        t.rinz_pgm = dlip->pointer;
970a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        t.rinz_agpmk = dlip->actinfo.Act_Grp_Mark;
971a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        _RINZSTAT(p);
972a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma disable_handler
973a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
974a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return 0;
975a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
976a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneraterr:
977a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!memcmp((char *) excbuf.Msg_Id, "MCH4421", 7))
978a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return 0;       /* Program cannot be reinitialized. */
979a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
980a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlseterror_from_exception(&excbuf);
981a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return -1;
982a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
983a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
984a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
985a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratvoid *
986a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlsym(void * handle, const char * symbol)
987a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
988a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
989a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlinfo * dlip;
990a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        void * p;
991a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int export_type;
992a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qus_EC_t errinfo;
993a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        volatile _INTRPT_Hndlr_Parms_T excbuf;
994a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        static int zero = 0;
995a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
996a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlthreadinit();
997a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
998a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!handle || !symbol) {
999a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlseterror_from_errno(EFAULT);
1000a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return (void *) NULL;
1001a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
1002a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1003a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlip = (dlinfo *) handle;
1004a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1005a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma exception_handler(error, excbuf, 0, _C2_MH_ESCAPE, _CTLA_HANDLE_NO_MSG)
1006a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        errinfo.Bytes_Provided = 0;
1007a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        QleGetExpLong(&dlip->actinfo.Act_Mark, &zero, &zero,
1008a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            (char *) symbol, &p, &export_type, &errinfo);
1009a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return p;
1010a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma disable_handler
1011a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1012a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneraterror:
1013a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlseterror_from_exception(&excbuf);
1014a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return (void *) NULL;
1015a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
1016a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1017a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1018a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratint
1019a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlclose(void * handle)
1020a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1021a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
1022a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlinfo * dlip;
1023a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        void (* _fini)(void);
1024a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1025a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlthreadinit();
1026a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1027a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!handle) {
1028a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlseterror_from_errno(EFAULT);
1029a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return -1;
1030a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
1031a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1032a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlip = (dlinfo *) handle;
1033a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1034a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlip->actcount) {
1035a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (--(dlip->actcount))
1036a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        return 0;
1037a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1038a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                if (_fini = dlsym(handle, "_fini"))
1039a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                        (*_fini)();
1040a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
1041a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1042a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return dlreinit(dlip);
1043a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
1044a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1045a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1046a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratstatic void *
1047a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlopenqsys(const Qp0l_QSYS_Info_t * dllinfo)
1048a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1049a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
1050a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlinfo * dlip;
1051a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlinfo * dlip2;
1052a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        void (* _init)(void);
1053a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        unsigned int i;
1054a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        _SYSPTR pgmptr;
1055a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        unsigned long long actmark;
1056a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qus_EC_t errinfo;
1057a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        char actmarkstr[2 * sizeof actmark + 1];
1058a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        static int actinfo_size = sizeof dlip->actinfo;
1059a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        volatile _INTRPT_Hndlr_Parms_T excbuf;
1060a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1061a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1062a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Capture any type of error and if any occurs,
1063a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***             return not found.
1064a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1065a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1066a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma exception_handler(error1, excbuf, 0, _C2_MH_ESCAPE, _CTLA_HANDLE_NO_MSG)
1067a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        pgmptr = rslvsp(WLI_SRVPGM, (char *) dllinfo->Obj_Name,
1068a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            (char *) dllinfo->Lib_Name ,_AUTH_NONE);
1069a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1070a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!pgmptr) {
1071a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = ENOENT;
1072a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return (void *) NULL;
1073a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
1074a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1075a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1076a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Create a new DLL info block.
1077a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1078a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1079a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlip = (dlinfo *) malloc(sizeof *dlip);
1080a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1081a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!dlip)
1082a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return (void *) NULL;           /* Cannot create block. */
1083a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma disable_handler
1084a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1085a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dllock();
1086a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1087a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma exception_handler(error2, excbuf, 0, _C2_MH_ESCAPE, _CTLA_HANDLE_NO_MSG)
1088a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        memset((char *) dlip, 0, sizeof *dlip);
1089a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlip->pointer = pgmptr;
1090a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1091a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1092a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Activate the DLL.
1093a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1094a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1095a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        errinfo.Bytes_Provided = 0;
1096a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        QleActBndPgmLong(&pgmptr, &actmark,
1097a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            &dlip->actinfo, &actinfo_size, &errinfo);
1098a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlip->actinfo.Act_Mark = actmark;
1099a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1100a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1101a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Dummy string encoding activation mark to use as hash table key.
1102a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1103a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1104a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        for (i = 0; actmark; actmark >>= 6)
1105a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                actmarkstr[i++] = 0x40 + (actmark & 0x3F);
1106a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1107a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        actmarkstr[i] = '\0';
1108a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1109a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1110a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Check if already activated.
1111a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1112a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1113a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlip2 = (dlinfo *) xmlHashLookup(dldir, actmarkstr);
1114a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1115a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (dlip2) {
1116a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                free((char *) dlip);
1117a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlip = dlip2;
1118a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
1119a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (xmlHashAddEntry(dldir, (const xmlChar *) actmarkstr, dlip)) {
1120a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlreinit(dlip);
1121a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                free((char *) dlip);
1122a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlunlock();
1123a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return (void *) NULL;
1124a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
1125a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma disable_handler
1126a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1127a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma exception_handler(error2, excbuf, 0, _C2_MH_ESCAPE, _CTLA_HANDLE_NO_MSG)
1128a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1129a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1130a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Bump activation counter.
1131a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1132a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1133a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!(dlip->actcount++) && (_init = dlsym(dlip, "_init")))
1134a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                (*_init)();
1135a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1136a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlunlock();
1137a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1138a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1139a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Return the handle.
1140a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1141a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1142a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return (void *) dlip;
1143a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat#pragma disable_handler
1144a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1145a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneraterror2:
1146a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        free((char *) dlip);
1147a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlunlock();
1148a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1149a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneraterror1:
1150a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlseterror_from_exception(&excbuf);
1151a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return (void *) NULL;
1152a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
1153a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1154a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1155a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratvoid *
1156a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monneratdlopen(const char * filename, int flag)
1157a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1158a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat{
1159a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        void * dlhandle;
1160a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        int sverrno;
1161a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        Qp0l_QSYS_Info_t dllinfo;
1162a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1163a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        sverrno = errno;
1164a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        errno = 0;
1165a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1166a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        dlthreadinit();
1167a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1168a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!filename) {
1169a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlseterror_from_errno(EFAULT);
1170a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                errno = sverrno;
1171a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                return NULL;
1172a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                }
1173a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1174a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        /**
1175a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     Try to locate the object in the following order:
1176a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     _       `filename' is an IFS path.
1177a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     _       `filename' is not a path and resides in one of
1178a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***                     LD_LIBRARY_PATH colon-separated paths.
1179a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     _       `filename' is not a path and resides in one of
1180a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***                     PATH colon-separated paths.
1181a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     _       `filename' is a DB2 path (as /library/object).
1182a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     _       `filename' is a qualified object name.
1183a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     _       `filename' is an object in *CURLIB.
1184a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        ***     _       `filename' is an object in *LIBL.
1185a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        **/
1186a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1187a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!dl_ifs_link(&dllinfo, filename) && dl_is_srvpgm(&dllinfo))
1188a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = dlopenqsys(&dllinfo);
1189a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!dl_path_link(&dllinfo,
1190a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            "LD_LIBRARY_PATH", filename, dl_is_srvpgm))
1191a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = dlopenqsys(&dllinfo);
1192a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!dl_path_link(&dllinfo, "PATH", filename, dl_is_srvpgm))
1193a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = dlopenqsys(&dllinfo);
1194a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!dl_DB2_path(&dllinfo, filename) && dl_is_srvpgm(&dllinfo))
1195a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = dlopenqsys(&dllinfo);
1196a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!dl_qualified_object(&dllinfo, filename) &&
1197a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            dl_is_srvpgm(&dllinfo))
1198a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = dlopenqsys(&dllinfo);
1199a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!dl_lib_object(&dllinfo, "*CURLIB", filename) &&
1200a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            dl_is_srvpgm(&dllinfo))
1201a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = dlopenqsys(&dllinfo);
1202a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else if (!dl_lib_object(&dllinfo, "*LIBL", filename) &&
1203a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat            dl_is_srvpgm(&dllinfo))
1204a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = dlopenqsys(&dllinfo);
1205a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        else
1206a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlhandle = NULL;
1207a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1208a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        if (!dlhandle && errno)
1209a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat                dlseterror_from_errno(errno);
1210a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat
1211a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        errno = sverrno;
1212a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat        return dlhandle;
1213a6c5b022f1d515f20beb01b70466893b64e33325Patrick Monnerat}
1214