File: usr_merge.cc

package info (click to toggle)
cruft-ng 0.4.7
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 152 kB
  • sloc: cpp: 779; ansic: 92; makefile: 37; sh: 9
file content (30 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (2)
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
#include <string>
#include <sys/stat.h>
#include "usr_merge.h"

bool check_link(string path)
{
	struct stat file_info;
	lstat(path.c_str(), &file_info);
	return S_ISLNK(file_info.st_mode);
}

string usr_merge(string path)
{
	static bool setup = false;
	static bool MERGED_BIN, MERGED_LIB, MERGED_SBIN;
	if (!setup)
	{
		MERGED_BIN=check_link("/bin");
		MERGED_LIB=check_link("/lib");
		MERGED_SBIN=check_link("/sbin");
		setup=true;
	}

	if ((MERGED_BIN and path.substr(0,5)=="/bin/")
	 or (MERGED_LIB and path.substr(0,5)=="/lib/")
	 or (MERGED_SBIN and path.substr(0,6)=="/sbin/"))
		return "/usr" + path;
	else
		return path;
}