Last active
August 26, 2022 01:19
-
-
Save stuaxo/79bcdcbaf9aa3b277207 to your computer and use it in GitHub Desktop.
Parse ld.so.conf and get all the directories from it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import abspath, isabs, join | |
from glob import glob | |
def parse_ldsoconf(filename="/etc/ld.so.conf"): | |
paths = set() | |
directory = dirname(abspath(filename)) | |
with open(filename) as f: | |
for line in (_line.rstrip() for _line in f.readlines()): | |
if line.startswith("include "): | |
wildcard = line.partition("include ")[-1:][0].rstrip() | |
if not isabs(wildcard): | |
wildcard = join(directory, wildcard) | |
for filename in glob(wildcard): | |
paths |= parse_ldsoconf(filename) | |
elif not line.startswith("#"): | |
if line: | |
paths.add(line) | |
return paths | |
parse_ldsoconf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment