-
Notifications
You must be signed in to change notification settings - Fork 5
/
usr_merge.cc
37 lines (33 loc) · 867 Bytes
/
usr_merge.cc
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
// Copyright © 2016 Alexandre Detiste <[email protected]>
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include <iostream>
#include <sys/stat.h>
#include "usr_merge.h"
static bool check_link(const string& path, const bool mandatory)
{
struct stat file_info;
if (lstat(path.c_str(), &file_info) < 0) {
if (mandatory) cerr << "Failed to stat '" << path << "': " << strerror(errno) << '\n';
return false;
}
return S_ISLNK(file_info.st_mode);
}
string usr_merge(const string& path)
{
static bool setup = false;
static bool MERGED;
if (!setup)
{
MERGED=check_link("/bin", true);
setup=true;
}
if (MERGED and (path.rfind("/bin/", 0) == 0
or path.rfind("/lib/", 0) == 0
or path.rfind("/lib32/", 0) == 0
or path.rfind("/lib64/", 0) == 0
or path.rfind("/sbin/", 0) == 0))
return "/usr" + path;
else
return path;
}