"use strict"; const Promise = require("bluebird"); const execFileAsync = require("./exec-file-async"); module.exports = function ldd(path) { return Promise.try(() => { return execFileAsync("ldd", [ path ]); }).then(({ stdout, stderr }) => { return stdout.split("\n").filter((line) => { return (line.trim().length > 0); }).map((line) => { let match = /^\s*(\S+)\s+=>\s+(.+)$/.exec(line); if (match == null) { if (!line.includes(".so")) { throw new Error(`Encountered unexpected output from ldd: ${line}`); } } else { return { library: match[1], location: (match[2] === "not found") ? null : match[2] }; } }).filter((result) => { return (result != null); }); }); };