core/LibrarySys.h
author Scott Ehlert <ds@alliedmods.net>
Fri Nov 06 16:24:40 2009 -0600 (2009-11-06)
changeset 2863 d740d9cdf53a
parent 2474 1f4345fb0f75
permissions -rw-r--r--
Added IMemoryUtils::ResolveSymbol() for resolving symbols hidden via GCC's -fvisibility=hidden (bug 4091, r=dvander,pred).

Right now, this is only used on L4D2 where it is needed.
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@370
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@370
    28
 *
dvander@370
    29
 * Version: $Id$
dvander@370
    30
 */
dvander@370
    31
dvander@141
    32
#ifndef _INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_
dvander@141
    33
#define _INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_
dvander@141
    34
dvander@141
    35
#include <ILibrarySys.h>
dvander@141
    36
#include "sm_platform.h"
dvander@141
    37
dvander@141
    38
using namespace SourceMod;
dvander@141
    39
dvander@141
    40
#if defined PLATFORM_WINDOWS
dvander@141
    41
typedef HMODULE		LibraryHandle;
dvander@351
    42
#elif defined PLATFORM_POSIX
dvander@141
    43
typedef void *		LibraryHandle;
dvander@141
    44
#endif
dvander@141
    45
dvander@141
    46
class CDirectory : public IDirectory
dvander@141
    47
{
dvander@141
    48
public:
dvander@141
    49
	CDirectory(const char *path);
dvander@141
    50
	~CDirectory();
dvander@141
    51
public:
faluco@641
    52
	bool MoreFiles();
faluco@641
    53
	void NextEntry();
faluco@641
    54
	const char *GetEntryName();
faluco@641
    55
	bool IsEntryDirectory();
faluco@641
    56
	bool IsEntryFile();
faluco@641
    57
	bool IsEntryValid();
dvander@141
    58
public:
dvander@141
    59
	bool IsValid();
dvander@141
    60
private:
dvander@141
    61
#if defined PLATFORM_WINDOWS
dvander@141
    62
	HANDLE m_dir;
dvander@141
    63
	WIN32_FIND_DATAA m_fd;
dvander@351
    64
#elif defined PLATFORM_POSIX
dvander@141
    65
	DIR *m_dir;
dvander@141
    66
	struct dirent *ep;
dvander@141
    67
	char m_origpath[PLATFORM_MAX_PATH];
dvander@141
    68
#endif
dvander@141
    69
};
dvander@141
    70
dvander@141
    71
class CLibrary : public ILibrary
dvander@141
    72
{
dvander@141
    73
public:
dvander@141
    74
	CLibrary(LibraryHandle me);
dvander@141
    75
	~CLibrary();
dvander@141
    76
public:
faluco@641
    77
	void CloseLibrary();
faluco@641
    78
	void *GetSymbolAddress(const char *symname);
dvander@141
    79
private:
dvander@141
    80
	LibraryHandle m_lib;
dvander@141
    81
};
dvander@141
    82
dvander@145
    83
class LibrarySystem : public ILibrarySys
dvander@141
    84
{
dvander@141
    85
public:
ds@755
    86
	ILibrary *OpenLibrary(const char *path, char *error, size_t maxlength);
faluco@641
    87
	IDirectory *OpenDirectory(const char *path);
faluco@641
    88
	void CloseDirectory(IDirectory *dir);
faluco@641
    89
	bool PathExists(const char *path);
faluco@641
    90
	bool IsPathFile(const char *path);
faluco@641
    91
	bool IsPathDirectory(const char *path);
ds@755
    92
	void GetPlatformError(char *error, size_t maxlength);
dvander@2474
    93
	void GetPlatformErrorEx(int code, char *error, size_t maxlength);
faluco@641
    94
	size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
ds@794
    95
	const char *GetFileExtension(const char *filename);
dvander@1192
    96
	bool CreateFolder(const char *path);
dvander@978
    97
	size_t GetFileFromPath(char *buffer, size_t maxlength, const char *path);
dvander@1738
    98
	bool FileTime(const char *path, FileTimeType type, time_t *pTime);
dvander@1974
    99
	void GetLoaderError(char *buffer, size_t maxlength);
dvander@141
   100
};
dvander@141
   101
dvander@141
   102
extern LibrarySystem g_LibSys;
dvander@141
   103
dvander@141
   104
#endif //_INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_