File: modules.h

package info (click to toggle)
ezquake 2.2%2Bgit20150324-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 6,996 kB
  • ctags: 16,582
  • sloc: ansic: 143,243; makefile: 339; tcl: 107; sh: 28
file content (79 lines) | stat: -rw-r--r-- 2,502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
Copyright (C) 2001-2002       A Nourai

This program 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; either version 2
of the License, or (at your option) any later version.

This program 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.  

See the included (GNU.txt) GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

	$Id: modules.h,v 1.9 2007-10-17 17:05:07 dkure Exp $
*/

#ifndef __MODULES_H__
#define __MODULES_H__

#ifndef _WIN32
#include <dlfcn.h>
#endif

#if (!defined WITH_PNG_STATIC || !defined WITH_JPEG_STATIC || defined WITH_MP3_PLAYER)
extern char _temp_modulename[MAX_OSPATH];


#ifdef _WIN32
#define QLIB_HANDLETYPE_T HINSTANCE
#define QLIB_LIBRARY_EXTENSION ".dll"
#define QLIB_LOADLIBRARY(lib)									\
	(																\
	snprintf(_temp_modulename, MAX_OSPATH, "%s.dll", lib),	\
	LoadLibrary(_temp_modulename)								\
	)
#define QLIB_GETPROCADDRESS(lib, func) GetProcAddress(lib, func)
#define QLIB_FREELIBRARY(lib) (FreeLibrary(lib), lib = NULL)
#else
#define QLIB_HANDLETYPE_T void *
#ifdef __APPLE__
#define QLIB_LIBRARY_EXTENSION ".dylib"
#else
#define QLIB_LIBRARY_EXTENSION ".so"
#endif
#define QLIB_LOADLIBRARY(lib)									\
	(																\
	snprintf(_temp_modulename, MAX_OSPATH, "%s.so", lib),	\
	dlopen(_temp_modulename, RTLD_NOW)							\
	)
#define QLIB_GETPROCADDRESS(lib, func) dlsym(lib, func)
#define QLIB_FREELIBRARY(lib) (dlclose(lib), lib = NULL)
#endif

#define QLIB_ERROR_MODULE_NOT_FOUND			-1
#define QLIB_ERROR_MODULE_MISSING_PROC		-2

typedef struct qlib_dllfunction_s {
	char *name;
	void **function;
} qlib_dllfunction_t;

typedef enum qlib_id_s {qlib_libpng, qlib_libjpeg, qlib_nummodules} qlib_id_t;

typedef void (*qlib_shutdown_fn) (void);

void QLib_Init (void);
void QLib_Shutdown (void);
void QLib_RegisterModule (qlib_id_t module, qlib_shutdown_fn shutdown);
qbool QLib_isModuleLoaded (qlib_id_t module);
qbool QLib_ProcessProcdef (QLIB_HANDLETYPE_T handle, qlib_dllfunction_t *procdefs, int size);
void QLib_MissingModuleError (int, char *libname, char *cmdline, char *features);
#endif

#endif /* !__MODULES_H__ */