Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / os / unix / library_loader_unix.cpp
blob471f1faa2a1534ee8a2dd546cad0d4ca82fd7d6f
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file library_loader_unix.cpp Implementation of the LibraryLoader for Linux / MacOS */
10 #include "../../stdafx.h"
12 #include <dlfcn.h>
14 #include "../../library_loader.h"
16 #include "../../safeguards.h"
18 /* Emscripten cannot dynamically load other files. */
19 #if defined(__EMSCRIPTEN__)
21 void *LibraryLoader::OpenLibrary(const std::string &)
23 this->error = "Dynamic loading is not supported on this platform.";
24 return nullptr;
27 void LibraryLoader::CloseLibrary()
31 void *LibraryLoader::GetSymbol(const std::string &)
33 this->error = "Dynamic loading is not supported on this platform.";
34 return nullptr;
37 #else
39 void *LibraryLoader::OpenLibrary(const std::string &filename)
41 void *h = dlopen(filename.c_str(), RTLD_NOW | RTLD_LOCAL);
42 if (h == nullptr) {
43 this->error = dlerror();
46 return h;
49 void LibraryLoader::CloseLibrary()
51 dlclose(this->handle);
54 void *LibraryLoader::GetSymbol(const std::string &symbol_name)
56 void *p = dlsym(this->handle, symbol_name.c_str());
57 if (p == nullptr) {
58 this->error = dlerror();
61 return p;
64 #endif /* __EMSCRIPTEN__ */