forked from TooTallNate/node-dlopen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
86 lines (76 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Module dependencies.
*/
const debug = require('debug')('dlopen');
const bindings = require('bindings')('binding');
class Library extends bindings.Library {
/**
* The `Library` class is an object-oriented wrapper around the
* dlopen(), dlclose(), dlsym() and dlerror() functions.
*
* @param {String} name - Library name or full filepath
* @api public
*/
constructor(name) {
if (name) {
// append the `ext` if necessary
const ext = exports.ext[process.platform];
if (name.substring(name.length - ext.length) !== ext) {
debug('appending dynamic lib suffix (%s)', ext, name);
name += ext;
}
} else {
// if no name was passed in then pass `null` to open the current process
name = null;
}
debug('library name', name);
super(name);
this.name = name;
}
/**
* Calls `uv_dlsym()` on this Library instance.
*
* A Node.js `Buffer` instance is returned which points to the
* memory location of the requested "symbol".
*
* @param {String} name - Symbol name to attempt to retrieve
* @return {Buffer} a Buffer instance pointing to the memory address of the symbol
* @api public
*/
get(name) {
debug('get()', name);
const sym = super.get(name);
// add some debugging info
sym.name = name;
sym.lib = this;
return sym;
}
/**
* Calls `uv_dlclose()` on this Library instance.
*
* @api public
*/
close() {
debug('close()');
super.close();
}
};
/**
* Map of `process.platform` values to their corresponding
* "dynamic library" file name extension.
*/
Library.ext = {
linux: '.so',
linux2: '.so',
sunos: '.so',
solaris: '.so',
freebsd: '.so',
openbsd: '.so',
darwin: '.dylib',
mac: '.dylib',
win32: '.dll'
};
/**
* Module exports.
*/
exports = module.exports = Library;