-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibmove.c
More file actions
55 lines (40 loc) · 1.18 KB
/
libmove.c
File metadata and controls
55 lines (40 loc) · 1.18 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <limits.h>
#include <stdlib.h>
#ifndef _ASSERT_H
#define _ASSERT_H
#ifdef NDEBUG
# define assert(EX)
#else
# define assert(EX) (void)((EX) || (__assert (#EX, __FILE__, __LINE__),0))
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern void __assert (const char *msg, const char *file, int line);
#ifdef __cplusplus
};
#endif
#endif
char buf[PATH_MAX + 1]; /* not sure about the "+ 1" */
//Changes the path to /app
char* fixpath(char* str)
{
if(!strncmp(str, "/usr", strlen("/usr"))) {
strcpy(str, realpath(str, buf)); //Run realpath on string to improve compatibility
memcpy(str, "/app", strlen("/app"));
printf("[libmv] New path is %s\n",str);
//We cannot use replace because if we use replace /usr/dir/usr/file will become /app/dir/app/file
//The currently used method removes the first 4 characters and inserts /app to the start.
}
return str;
}
int open(const char *fn, int flags) {
static int (*real_open)(const char *fn, int flags);
if (!real_open) {
real_open = dlsym(RTLD_NEXT, "open");
}
return real_open(fixpath(fn), flags);
}