Commit 728b6fc5 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

libwine: Fully dereference the /proc/self/exe symbolic link.

Linux will do it for us but not NetBSD. That is, if foo is an executable that prints the path /proc/self/exe points to, on Linux one gets: $ ./foo /tmp/foo $ ln -s foo bar $ ln -s bar babar $ /tmp/babar /tmp/foo But on NetBSD one gets instead: $ ./foo /tmp/./foo $ ln -s foo bar $ ln -s bar babar $ /tmp/babar /tmp/babar Fully dereferencing /proc/self/exe is necessary to be able to run both 32 and 64 bit executables from the build tree. Signed-off-by: 's avatarFrancois Gouget <fgouget@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 04f75040
...@@ -164,33 +164,15 @@ static char *get_runtime_libdir(void) ...@@ -164,33 +164,15 @@ static char *get_runtime_libdir(void)
/* read a symlink and return its directory */ /* read a symlink and return its directory */
static char *symlink_dirname( const char *name ) static char *symlink_dirname( const char *name )
{ {
char *p, *buffer, *absdir = NULL; char *p, *fullpath = realpath( name, NULL );
int ret, size;
for (size = 256; ; size *= 2) if (fullpath)
{ {
if (!(buffer = malloc( size ))) return NULL; p = strrchr( fullpath, '/' );
if ((ret = readlink( name, buffer, size )) == -1) break; if (p == fullpath) p++;
if (ret != size) if (p) *p = 0;
{
buffer[ret] = 0;
if (!(p = strrchr( buffer, '/' ))) break;
if (p == buffer) p++;
*p = 0;
if (buffer[0] == '/') return buffer;
/* make it absolute */
absdir = xmalloc( strlen(name) + strlen(buffer) + 1 );
strcpy( absdir, name );
if (!(p = strrchr( absdir, '/' ))) break;
strcpy( p + 1, buffer );
free( buffer );
return absdir;
}
free( buffer );
} }
free( buffer ); return fullpath;
free( absdir );
return NULL;
} }
/* return the directory that contains the main exe at run-time */ /* return the directory that contains the main exe at run-time */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment