10 #define PREFIX "/rootfs"
13 const char *add_prefix(const char *orig, char *prefixed) {
14 if ((strncmp(orig, "/proc", 5) != 0) && (strncmp(orig, "/sys", 4) != 0))
17 int status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig);
18 if ((unsigned int)status >= BUFSIZE) {
19 error(status, ENAMETOOLONG,
20 "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX,
23 } else if (status < 1) {
25 "adding '%s' prefix to file path failed: '%s' -> '%s'", PREFIX,
29 return (const char *)prefixed;
33 FILE *fopen(const char *path, const char *mode) {
34 char filename[BUFSIZE] = "\0";
36 FILE *(*original_fopen)(const char *, const char *);
37 original_fopen = dlsym(RTLD_NEXT, "fopen");
39 return (*original_fopen)(add_prefix(path, filename), mode);
42 DIR *opendir(const char *name) {
43 char filename[BUFSIZE] = "\0";
45 DIR *(*original_opendir)(const char *);
46 original_opendir = dlsym(RTLD_NEXT, "opendir");
48 return (*original_opendir)(add_prefix(name, filename));
51 int *open(const char *pathname, int flags) {
52 char filename[BUFSIZE] = "\0";
54 int *(*original_open)(const char *, int);
55 original_open = dlsym(RTLD_NEXT, "open");
57 return (*original_open)(add_prefix(pathname, filename), flags);