summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: eec0cd9)
raw | patch | inline | side by side (parent: eec0cd9)
author | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Tue, 29 Nov 2016 11:21:29 +0000 (12:21 +0100) | ||
committer | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Tue, 29 Nov 2016 11:21:29 +0000 (12:21 +0100) |
contrib/docker/rootfs_prefix/rootfs_prefix.c | patch | blob | history |
diff --git a/contrib/docker/rootfs_prefix/rootfs_prefix.c b/contrib/docker/rootfs_prefix/rootfs_prefix.c
index d41f06257f14139d798a2bf74b80738283301e7b..c27a67afd12eeebfcc94dfba288c5a464bbe4373 100644 (file)
#define _GNU_SOURCE
-#include <stdio.h>
-#include <error.h>
+#include <dirent.h>
#include <dlfcn.h>
-#include <string.h>
#include <errno.h>
-#include <dirent.h>
+#include <error.h>
+#include <stdio.h>
+#include <string.h>
#define PREFIX "/rootfs"
#define BUFSIZE 256
const char *add_prefix(const char *orig, char *prefixed) {
- int status;
- int errno;
-
- if ((strncmp(orig, "/proc", 5) == 0) ||
- (strncmp(orig, "/sys", 4) == 0)) {
-
- status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig);
- if ((unsigned int)status >= BUFSIZE) {
- error(status, ENAMETOOLONG, "'%s' got truncated when adding '%s' prefix: '%s'",
- orig, PREFIX, prefixed);
- return orig;
- } else if (status < 1) {
- error(status, errno, "adding '%s' prefix to file path failed: '%s' -> '%s'",
- PREFIX, orig, prefixed);
- return orig;
- } else {
- return (const char*) prefixed;
- }
-
- } else {
- return orig;
- }
+ int status;
+ int errno;
+
+ if ((strncmp(orig, "/proc", 5) == 0) || (strncmp(orig, "/sys", 4) == 0)) {
+
+ status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig);
+ if ((unsigned int)status >= BUFSIZE) {
+ error(status, ENAMETOOLONG,
+ "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX,
+ prefixed);
+ return orig;
+ } else if (status < 1) {
+ error(status, errno,
+ "adding '%s' prefix to file path failed: '%s' -> '%s'", PREFIX,
+ orig, prefixed);
+ return orig;
+ } else {
+ return (const char *)prefixed;
+ }
+
+ } else {
+ return orig;
+ }
}
FILE *fopen(const char *path, const char *mode) {
- char filename[BUFSIZE] = "\0";
+ char filename[BUFSIZE] = "\0";
- FILE *(*original_fopen)(const char*, const char*);
- original_fopen = dlsym(RTLD_NEXT, "fopen");
+ FILE *(*original_fopen)(const char *, const char *);
+ original_fopen = dlsym(RTLD_NEXT, "fopen");
- return (*original_fopen)(add_prefix(path, filename), mode);
+ return (*original_fopen)(add_prefix(path, filename), mode);
}
DIR *opendir(const char *name) {
- char filename[BUFSIZE] = "\0";
+ char filename[BUFSIZE] = "\0";
- DIR *(*original_opendir)(const char*);
- original_opendir = dlsym(RTLD_NEXT, "opendir");
+ DIR *(*original_opendir)(const char *);
+ original_opendir = dlsym(RTLD_NEXT, "opendir");
- return (*original_opendir)(add_prefix(name, filename));
+ return (*original_opendir)(add_prefix(name, filename));
}
int *open(const char *pathname, int flags) {
- char filename[BUFSIZE] = "\0";
+ char filename[BUFSIZE] = "\0";
- int *(*original_open)(const char*, int);
- original_open = dlsym(RTLD_NEXT, "open");
+ int *(*original_open)(const char *, int);
+ original_open = dlsym(RTLD_NEXT, "open");
- return (*original_open)(add_prefix(pathname, filename), flags);
+ return (*original_open)(add_prefix(pathname, filename), flags);
}