diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 19:15:25 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 19:15:25 +0000 |
commit | df9167beda5d69796316c3c862c849c73433c78a (patch) | |
tree | 620511ad8643be248f01b3c164926180d93631da /base/native_library_posix.cc | |
parent | ddbfc54b5c5739d44d00dc428b362ead22cd755e (diff) | |
download | chromium_src-df9167beda5d69796316c3c862c849c73433c78a.zip chromium_src-df9167beda5d69796316c3c862c849c73433c78a.tar.gz chromium_src-df9167beda5d69796316c3c862c849c73433c78a.tar.bz2 |
rename some _linux files to _posix and introduce os_bsd
The os_bsd variable is only available on FreeBSD and OpenBSD.
Later on others like NetBSD and DragonflyBSD can be added.
This variable was introduced in order to have shorter
conditions in the gyp files.
BUG=
TEST=compile
Patch by Robert Nagy <robert.nagy@gmail.com>
Review URL: http://codereview.chromium.org/8567001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/native_library_posix.cc')
-rw-r--r-- | base/native_library_posix.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/base/native_library_posix.cc b/base/native_library_posix.cc new file mode 100644 index 0000000..4b82ff4 --- /dev/null +++ b/base/native_library_posix.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/native_library.h" + +#include <dlfcn.h> + +#include "base/file_path.h" +#include "base/logging.h" +#include "base/threading/thread_restrictions.h" +#include "base/utf_string_conversions.h" + +namespace base { + +// static +NativeLibrary LoadNativeLibrary(const FilePath& library_path, + std::string* error) { + // dlopen() opens the file off disk. + base::ThreadRestrictions::AssertIOAllowed(); + + // We deliberately do not use RTLD_DEEPBIND. For the history why, please + // refer to the bug tracker. Some useful bug reports to read include: + // http://crbug.com/17943, http://crbug.com/17557, http://crbug.com/36892, + // and http://crbug.com/40794. + void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY); + if (!dl && error) + *error = dlerror(); + + return dl; +} + +// static +void UnloadNativeLibrary(NativeLibrary library) { + int ret = dlclose(library); + if (ret < 0) { + DLOG(ERROR) << "dlclose failed: " << dlerror(); + NOTREACHED(); + } +} + +// static +void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, + const char* name) { + return dlsym(library, name); +} + +// static +string16 GetNativeLibraryName(const string16& name) { + return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); +} + +} // namespace base |