zoslib
z/OS C/C++ Library
Loading...
Searching...
No Matches
zos-setlibpath.h
Go to the documentation of this file.
1
2// Licensed Materials - Property of IBM
3// ZOSLIB
4// (C) Copyright IBM Corp. 2021. All Rights Reserved.
5// US Government Users Restricted Rights - Use, duplication
6// or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
8
9#ifndef ZOS_SETLIBPATH_H_
10#define ZOS_SETLIBPATH_H_
11
12#include "zos-macros.h"
13
14#include <libgen.h>
15#include <sstream>
16#include <sys/ps.h>
17
19public:
21 std::vector<char> argv(512, 0);
22 std::vector<char> parent(512, 0);
23 W_PSPROC buf;
24 int token = 0;
25 pid_t mypid = getpid();
26 memset(&buf, 0, sizeof(buf));
27 buf.ps_pathlen = argv.size();
28 buf.ps_pathptr = &argv[0];
29 while ((token = w_getpsent(token, &buf, sizeof(buf))) > 0) {
30 if (buf.ps_pid == mypid) {
31 /* Found our process. */
32 /*
33 * Resolve path to find true location of executable; don't use an
34 * overridden realpath function from zoslib, since this header may
35 * be used in an exe before libzoslib.so has been loaded.
36 */
37 if (__realpath_a(&argv[0], &parent[0]) == NULL)
38 break;
39
40 /* Get parent directory. */
41 dirname(&parent[0]);
42
43 /* Get parent's parent directory. */
44 std::vector<char> parent2(parent.begin(), parent.end());
45 dirname(&parent2[0]);
46
47 /* Append new paths to libpath. */
48 std::ostringstream libpath;
49 libpath << getenv("LIBPATH");
50 libpath << ":" << &parent[0] << "/lib.target/";
51 libpath << ":" << &parent[0] << "/lib/";
52 libpath << ":" << &parent2[0] << "/lib/";
53 setenv("LIBPATH", libpath.str().c_str(), 1);
54 break;
55 }
56 }
57 }
58};
59
60#endif // ZOS_SETLIBPATH_H_
Definition zos-setlibpath.h:18
__setlibpath()
Definition zos-setlibpath.h:20
#define __Z_EXPORT
Definition zos-macros.h:13