3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
20 #define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
24 * @brief Defines platform-dependent operations, such as opening libraries and files.
27 #include <IShareSys.h>
31 #define SMINTERFACE_LIBRARYSYS_NAME "ILibrarySys"
32 #define SMINTERFACE_LIBRARYSYS_VERSION 1
37 /** Virtual destructor (calls CloseLibrary) */
43 * @brief Closes dynamic library and invalidates pointer.
45 virtual void CloseLibrary() =0;
48 * @brief Retrieves a symbol pointer from the dynamic library.
50 * @param symname Symbol name.
51 * @return Symbol pointer, NULL if not found.
53 virtual void *GetSymbolAddress(const char *symname) =0;
57 * @brief Directory browsing abstraction.
62 /** Virtual destructor */
68 * @brief Returns true if there are more files to read, false otherwise.
70 virtual bool MoreFiles() =0;
73 * @brief Advances to the next entry in the stream.
75 virtual void NextEntry() =0;
78 * @brief Returns the name of the current entry.
80 virtual const char *GetEntryName() =0;
83 * @brief Returns whether the current entry is a directory.
85 virtual bool IsEntryDirectory() =0;
88 * @brief Returns whether the current entry is a file.
90 virtual bool IsEntryFile() =0;
93 * @brief Returns true if the current entry is valid
94 * (Used similarly to MoreFiles).
96 virtual bool IsEntryValid() =0;
100 * @brief Contains various operating system specific code.
102 class ILibrarySys : public SMInterface
105 virtual const char *GetInterfaceName()
107 return SMINTERFACE_LIBRARYSYS_NAME;
109 virtual unsigned int GetInterfaceVersion()
111 return SMINTERFACE_LIBRARYSYS_VERSION;
115 * @brief Opens a dynamic library file.
117 * @param path Path to library file (.dll/.so).
118 * @param error Buffer for any error message (may be NULL).
119 * @param err_max Maximum length of error buffer.
120 * @return Pointer to an ILibrary, NULL if failed.
122 virtual ILibrary *OpenLibrary(const char *path, char *error, size_t err_max) =0;
125 * @brief Opens a directory for reading.
127 * @param path Path to directory.
128 * @return Pointer to an IDirectory, NULL if failed.
130 virtual IDirectory *OpenDirectory(const char *path) =0;
133 * @brief Closes a directory and frees its handle.
135 * @param dir Pointer to IDirectory.
137 virtual void CloseDirectory(IDirectory *dir) =0;
140 * @brief Returns true if a path exists.
142 virtual bool PathExists(const char *path) =0;
145 * @brief Returns true if the path is a normal file.
147 virtual bool IsPathFile(const char *path) =0;
150 * @brief Returns true if the path is a normal directory.
152 virtual bool IsPathDirectory(const char *path) =0;
155 * @brief Gets a platform-specific error message.
156 * This should only be called when an ILibrary function fails.
157 * Win32 equivalent: GetLastError() + FormatMessage()
158 * POSIX equivalent: errno + strerror()
160 * @param error Error message buffer.
161 * @param err_max Maximum length of error buffer.
163 virtual void GetPlatformError(char *error, size_t err_max) =0;
166 * @brief Formats a string similar to snprintf(), except
167 * corrects all non-platform compatible path separators to be
168 * the correct platform character.
170 * @param buffer Output buffer pointer.
171 * @param maxlength Output buffer size.
172 * @param pathfmt Format string of path.
173 * @param ... Format string arguments.
175 virtual size_t PathFormat(char *buffer, size_t maxlength, const char *pathfmt, ...) =0;
179 #endif //_INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_