10 #define PREFIX "/rootfs"
13 const char *add_prefix(const char *orig, char *prefixed) {
17 if ((strncmp(orig, "/proc", 5) == 0) || (strncmp(orig, "/sys", 4) == 0)) {
19 status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig);
20 if ((unsigned int)status >= BUFSIZE) {
21 error(status, ENAMETOOLONG,
22 "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX,
25 } else if (status < 1) {
27 "adding '%s' prefix to file path failed: '%s' -> '%s'", PREFIX,
31 return (const char *)prefixed;
39 FILE *fopen(const char *path, const char *mode) {
40 char filename[BUFSIZE] = "\0";
42 FILE *(*original_fopen)(const char *, const char *);
43 original_fopen = dlsym(RTLD_NEXT, "fopen");
45 return (*original_fopen)(add_prefix(path, filename), mode);
48 DIR *opendir(const char *name) {
49 char filename[BUFSIZE] = "\0";
51 DIR *(*original_opendir)(const char *);
52 original_opendir = dlsym(RTLD_NEXT, "opendir");
54 return (*original_opendir)(add_prefix(name, filename));
57 int *open(const char *pathname, int flags) {
58 char filename[BUFSIZE] = "\0";
60 int *(*original_open)(const char *, int);
61 original_open = dlsym(RTLD_NEXT, "open");
63 return (*original_open)(add_prefix(pathname, filename), flags);