newlib/winsup/cygwin/dlfcn.cc
Corinna Vinschen e4b575030b Add case-sensitivity.
Unconditionally handle mount points case-sensitive.
	Unconditionally handle virtual paths case-sensitive.
	Unconditionally handle registry paths case-insensitive.
	Otherwise, accommodate case-sensitivity of given path throughout.
	* cygheap.cc (cygheap_root::set): Get additional caseinsensitive
	parameter and store it.
	* cygheap.h (struct cygheap_root_mount_info): Add member
	caseinsensitive.
	* dlfcn.cc (get_full_path_of_dll): Drop PC_NOFULL parameter from call
	to path_conv::check.
	* environ.cc (pcheck_case): Remove.
	(check_case_init): Remove.
	(known): Drop "check_case" option.
	* exceptions.cc (open_stackdumpfile): Add comment.
	* fhandler.cc (fhandler_base::get_default_fmode): Call pathmatch
	instead of strcasematch.
	* fhandler_disk_file.cc: Accommodate case-sensitivity of given path
	throughout.
	(__DIR_mounts::check_mount): Unconditionally check virtual paths
	case-sensitive.
	(fhandler_disk_file::link): Drop case clash handling.
	(fhandler_disk_file::open): Ditto.
	(fhandler_disk_file::readdir_helper): Drop managed mount code.
	* mount.cc: Remove managed mount code and datastructures.
	(struct opt): Remove "managed" option.  Add "posix=0" and "posix=1"
	options.
	(fillout_mntent): Remove "managed" output.  Add "posix" output.
	* path.cc (struct symlink_info): Remove case_clash member and
	case_check method.
	(pcheck_case): Remove.
	(path_prefix_p): Take additional bool parameter "caseinsensitive".
	(pathnmatch): Ditto.
	(pathmatch): Ditto.
	(mkrelpath): Ditto.
	(fs_info::update): Set caseinsensitive flag according to file system
	name and FILE_CASE_SENSITIVE_SEARCH flag.  Add comment.
	(tfx_chars_managed): Remove.
	(transform_chars): Drop "managed" parameter.  Always use tfx_chars.
	(get_nt_native_path): Drop "managed" parameter.  Make sure drive letters
	are always upper case.
	(getfileattr): Change second parameter to denote caseinsensitivity.
	(path_conv::check): Initialize caseinsensitive to OBJ_CASE_INSENSITIVE.
	Set caseinsensitive according to global obcaseinsensitive flag, file
	system case sensitivity and MOUNT_NOPOSIX mount flag.
	Drop case_clash and all the related code.
	(symlink_worker): Drop case clash handling.
	(symlink_info::set): Drop setting case_clash.
	(symlink_info::case_check): Remove.
	(cwdstuff::set): Add comment.
	(etc::init): Take path_conv instead of PUNICODE_STRING as parameter to
	allow case sensitivity.
	* path.h (enum pathconv_arg): Drop PC_SYM_IGNORE.
	(enum case_checking): Remove.
	(enum path_types): Drop PATH_ENC, add PATH_NOPOSIX flag.
	(struct fs_info): Add caseinsensitive flag and accessor methods.
	(class path_conv): Add caseinsensitive member and define
	objcaseinsensitive method.  Drop case_clash member and isencoded method.
	(pathmatch): Change prototype according to above change.
	(pathnmatch): Ditto.
	(path_prefix_p): Ditto.
	(get_nt_native_path): Ditto.
	(class etc): Ditto.
	(fnunmunge): Remove prototype.
	* shared.cc (shared_info::init_obcaseinsensitive): Initialize
	obcaseinsensitive flag from obcaseinsensitive registry value.
	(shared_info::initialize): Call init_obcaseinsensitive here by the
	first process creating the shared memory.
	* shared_info.h (mount_item::fnmunge): Remove.
	(shared_info::obcaseinsensitive): Rename from obcaseinsensitivity.
	(shared_info::init_obcaseinsensitive): Declare.
	* syscalls.cc (try_to_bin): Add comment.
	* include/sys/mount.h (MOUNT_ENC): Remove flag.
	(MOUNT_NOPOSIX): Add flag.
2008-07-16 20:20:45 +00:00

163 lines
3.7 KiB
C++

/* dlfcn.cc
Copyright 1998, 2000, 2001, 2002, 2003, 2004, 2008 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <psapi.h>
#include <stdlib.h>
#include <ctype.h>
#include "path.h"
#include "perprocess.h"
#include "dlfcn.h"
#include "cygtls.h"
#include "tls_pbuf.h"
static void __stdcall
set_dl_error (const char *str)
{
strcpy (_my_tls.locals.dl_buffer, strerror (get_errno ()));
_my_tls.locals.dl_error = 1;
}
/* Look for an executable file given the name and the environment
variable to use for searching (eg., PATH); returns the full
pathname (static buffer) if found or NULL if not. */
inline const char * __stdcall
check_path_access (const char *mywinenv, const char *name, path_conv& buf)
{
return find_exec (name, buf, mywinenv, FE_NNF | FE_NATIVE | FE_CWD | FE_DLL);
}
/* Search LD_LIBRARY_PATH for dll, if it exists.
Return Windows version of given path. */
static const char * __stdcall
get_full_path_of_dll (const char* str, char *name)
{
int len = strlen (str);
/* empty string or too long to be legal win32 pathname? */
if (len == 0 || len >= PATH_MAX)
return str; /* Yes. Let caller deal with it. */
const char *ret;
strcpy (name, str); /* Put it somewhere where we can manipulate it. */
/* Add extension if necessary */
if (str[len - 1] != '.')
{
/* Add .dll only if no extension provided. */
const char *p = strrchr (str, '.');
if (!p || strpbrk (p, "\\/"))
strcat (name, ".dll");
}
path_conv real_filename;
if (isabspath (name) ||
(ret = check_path_access ("LD_LIBRARY_PATH=", name, real_filename)
?: check_path_access ("/usr/lib", name, real_filename)) == NULL)
real_filename.check (name, PC_SYM_FOLLOW | PC_NULLEMPTY); /* Convert */
if (!real_filename.error)
ret = strcpy (name, real_filename.get_win32 ());
else
{
set_errno (real_filename.error);
ret = NULL;
}
return ret;
}
void *
dlopen (const char *name, int)
{
void *ret;
if (name == NULL)
ret = (void *) GetModuleHandle (NULL); /* handle for the current module */
else
{
tmp_pathbuf tp;
char *buf = tp.c_get ();
/* handle for the named library */
const char *fullpath = get_full_path_of_dll (name, buf);
if (!fullpath)
ret = NULL;
else
{
ret = (void *) LoadLibrary (fullpath);
if (ret == NULL)
__seterrno ();
}
}
if (!ret)
set_dl_error ("dlopen");
debug_printf ("ret %p", ret);
return ret;
}
void *
dlsym (void *handle, const char *name)
{
void *ret = NULL;
if (handle == RTLD_DEFAULT)
{ /* search all modules */
HANDLE cur_proc = GetCurrentProcess ();
HMODULE *modules;
DWORD needed, i;
if (!EnumProcessModules (cur_proc, NULL, 0, &needed))
{
dlsym_fail:
set_dl_error ("dlsym");
return NULL;
}
modules = (HMODULE*) alloca (needed);
if (!EnumProcessModules (cur_proc, modules, needed, &needed))
goto dlsym_fail;
for (i = 0; i < needed / sizeof (HMODULE); i++)
if ((ret = (void *) GetProcAddress (modules[i], name)))
break;
}
else
ret = (void *) GetProcAddress ((HMODULE)handle, name);
if (!ret)
set_dl_error ("dlsym");
debug_printf ("ret %p", ret);
return ret;
}
int
dlclose (void *handle)
{
int ret = -1;
if (handle == GetModuleHandle (NULL) || FreeLibrary ((HMODULE) handle))
ret = 0;
if (ret)
set_dl_error ("dlclose");
return ret;
}
char *
dlerror ()
{
char *res;
if (!_my_tls.locals.dl_error)
res = NULL;
else
{
_my_tls.locals.dl_error = 0;
res = _my_tls.locals.dl_buffer;
}
return res;
}