Skip to content

Commit 261212a

Browse files
committed
djdev64: fix emu_dlmopen()
It wasn't actually working, since glibc checks not only names but also file inodes. So to really trick it, we need to copy file. Symlink does not help.
1 parent b5d09cd commit 261212a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/djdev64/djdev64.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ static char *findmnt(const char *path)
127127

128128
static const char *var_list[] = { "_crt0_startup_flags", NULL };
129129

130+
static int cp(const char *from, const char *to)
131+
{
132+
char buf[1024];
133+
size_t sz = snprintf(buf, sizeof(buf), "cp %s %s", from, to);
134+
if (sz >= sizeof(buf))
135+
return -1;
136+
return system(buf);
137+
}
138+
130139
static void *emu_dlmopen(int handle, const char *filename, int flags,
131140
char **r_path)
132141
{
@@ -144,9 +153,10 @@ static void *emu_dlmopen(int handle, const char *filename, int flags,
144153
else
145154
p++;
146155
unlink(path);
147-
err = symlink(filename, path);
156+
/* glibc compares inodes from stat(), so symlinks do not help - use cp */
157+
err = cp(filename, path);
148158
if (err) {
149-
perror("symlink()");
159+
fprintf(stderr, "cp() failed");
150160
goto err_free;
151161
}
152162
ret = dlopen(path, flags);

0 commit comments

Comments
 (0)