mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-06 15:47:20 +02:00
Rename variables and functions that had an underscore prefix
Ensures we conform better to C standards
This commit is contained in:
parent
752d877196
commit
d9727e9d38
@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static char _client_error_string[512] = { 0 };
|
static char internal_gamemode_client_error_string[512] = { 0 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load libgamemode dynamically to dislodge us from most dependencies.
|
* Load libgamemode dynamically to dislodge us from most dependencies.
|
||||||
@ -46,27 +46,27 @@ static char _client_error_string[512] = { 0 };
|
|||||||
* See SDL2 for an example of the reasoning behind this in terms of
|
* See SDL2 for an example of the reasoning behind this in terms of
|
||||||
* dynamic versioning as well.
|
* dynamic versioning as well.
|
||||||
*/
|
*/
|
||||||
static volatile int _libgamemode_loaded = 1;
|
static volatile int internal_libgamemode_loaded = 1;
|
||||||
|
|
||||||
/* Typedefs for the functions to load */
|
/* Typedefs for the functions to load */
|
||||||
typedef int (*_gamemode_request_start)(void);
|
typedef int (*internal_gamemode_request_start)(void);
|
||||||
typedef int (*_gamemode_request_end)(void);
|
typedef int (*internal_gamemode_request_end)(void);
|
||||||
typedef const char *(*_gamemode_error_string)(void);
|
typedef const char *(*internal_gamemode_error_string)(void);
|
||||||
|
|
||||||
/* Storage for functors */
|
/* Storage for functors */
|
||||||
static _gamemode_request_start _REAL_gamemode_request_start = NULL;
|
static internal_gamemode_request_start REAL_internal_gamemode_request_start = NULL;
|
||||||
static _gamemode_request_end _REAL_gamemode_request_end = NULL;
|
static internal_gamemode_request_end REAL_internal_gamemode_request_end = NULL;
|
||||||
static _gamemode_error_string _REAL_gamemode_error_string = NULL;
|
static internal_gamemode_error_string REAL_internal_gamemode_error_string = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper to perform the symbol binding safely.
|
* Internal helper to perform the symbol binding safely.
|
||||||
*
|
*
|
||||||
* Returns 0 on success and -1 on failure
|
* Returns 0 on success and -1 on failure
|
||||||
*/
|
*/
|
||||||
__attribute__((always_inline)) static inline int _bind_libgamemode_symbol(void *handle,
|
__attribute__((always_inline)) static inline int internal_bind_libgamemode_symbol(void *handle,
|
||||||
const char *name,
|
const char *name,
|
||||||
void **out_func,
|
void **out_func,
|
||||||
size_t func_size)
|
size_t func_size)
|
||||||
{
|
{
|
||||||
void *symbol_lookup = NULL;
|
void *symbol_lookup = NULL;
|
||||||
char *dl_error = NULL;
|
char *dl_error = NULL;
|
||||||
@ -75,7 +75,10 @@ __attribute__((always_inline)) static inline int _bind_libgamemode_symbol(void *
|
|||||||
symbol_lookup = dlsym(handle, name);
|
symbol_lookup = dlsym(handle, name);
|
||||||
dl_error = dlerror();
|
dl_error = dlerror();
|
||||||
if (dl_error || !symbol_lookup) {
|
if (dl_error || !symbol_lookup) {
|
||||||
snprintf(_client_error_string, sizeof(_client_error_string), "dlsym failed - %s", dl_error);
|
snprintf(internal_gamemode_client_error_string,
|
||||||
|
sizeof(internal_gamemode_client_error_string),
|
||||||
|
"dlsym failed - %s",
|
||||||
|
dl_error);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,11 +92,11 @@ __attribute__((always_inline)) static inline int _bind_libgamemode_symbol(void *
|
|||||||
*
|
*
|
||||||
* Returns 0 on success and -1 on failure
|
* Returns 0 on success and -1 on failure
|
||||||
*/
|
*/
|
||||||
__attribute__((always_inline)) static inline int _load_libgamemode(void)
|
__attribute__((always_inline)) static inline int internal_load_libgamemode(void)
|
||||||
{
|
{
|
||||||
/* We start at 1, 0 is a success and -1 is a fail */
|
/* We start at 1, 0 is a success and -1 is a fail */
|
||||||
if (_libgamemode_loaded != 1) {
|
if (internal_libgamemode_loaded != 1) {
|
||||||
return _libgamemode_loaded;
|
return internal_libgamemode_loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Anonymous struct type to define our bindings */
|
/* Anonymous struct type to define our bindings */
|
||||||
@ -103,14 +106,14 @@ __attribute__((always_inline)) static inline int _load_libgamemode(void)
|
|||||||
size_t func_size;
|
size_t func_size;
|
||||||
} bindings[] = {
|
} bindings[] = {
|
||||||
{ "real_gamemode_request_start",
|
{ "real_gamemode_request_start",
|
||||||
(void **)&_REAL_gamemode_request_start,
|
(void **)&REAL_internal_gamemode_request_start,
|
||||||
sizeof(_REAL_gamemode_request_start) },
|
sizeof(REAL_internal_gamemode_request_start) },
|
||||||
{ "real_gamemode_request_end",
|
{ "real_gamemode_request_end",
|
||||||
(void **)&_REAL_gamemode_request_end,
|
(void **)&REAL_internal_gamemode_request_end,
|
||||||
sizeof(_REAL_gamemode_request_end) },
|
sizeof(REAL_internal_gamemode_request_end) },
|
||||||
{ "real_gamemode_error_string",
|
{ "real_gamemode_error_string",
|
||||||
(void **)&_REAL_gamemode_error_string,
|
(void **)&REAL_internal_gamemode_error_string,
|
||||||
sizeof(_REAL_gamemode_error_string) },
|
sizeof(REAL_internal_gamemode_error_string) },
|
||||||
};
|
};
|
||||||
|
|
||||||
void *libgamemode = NULL;
|
void *libgamemode = NULL;
|
||||||
@ -118,11 +121,11 @@ __attribute__((always_inline)) static inline int _load_libgamemode(void)
|
|||||||
/* Try and load libgamemode */
|
/* Try and load libgamemode */
|
||||||
libgamemode = dlopen("libgamemode.so", RTLD_NOW);
|
libgamemode = dlopen("libgamemode.so", RTLD_NOW);
|
||||||
if (!libgamemode) {
|
if (!libgamemode) {
|
||||||
snprintf(_client_error_string,
|
snprintf(internal_gamemode_client_error_string,
|
||||||
sizeof(_client_error_string),
|
sizeof(internal_gamemode_client_error_string),
|
||||||
"dylopen failed - %s",
|
"dylopen failed - %s",
|
||||||
dlerror());
|
dlerror());
|
||||||
_libgamemode_loaded = -1;
|
internal_libgamemode_loaded = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,17 +133,17 @@ __attribute__((always_inline)) static inline int _load_libgamemode(void)
|
|||||||
for (size_t i = 0; i < sizeof(bindings) / sizeof(bindings[0]); i++) {
|
for (size_t i = 0; i < sizeof(bindings) / sizeof(bindings[0]); i++) {
|
||||||
struct binding *binder = &bindings[i];
|
struct binding *binder = &bindings[i];
|
||||||
|
|
||||||
if (_bind_libgamemode_symbol(libgamemode,
|
if (internal_bind_libgamemode_symbol(libgamemode,
|
||||||
binder->name,
|
binder->name,
|
||||||
binder->functor,
|
binder->functor,
|
||||||
binder->func_size) != 0) {
|
binder->func_size) != 0) {
|
||||||
_libgamemode_loaded = -1;
|
internal_libgamemode_loaded = -1;
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
_libgamemode_loaded = 0;
|
internal_libgamemode_loaded = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,11 +153,11 @@ __attribute__((always_inline)) static inline int _load_libgamemode(void)
|
|||||||
__attribute__((always_inline)) static inline const char *gamemode_error_string(void)
|
__attribute__((always_inline)) static inline const char *gamemode_error_string(void)
|
||||||
{
|
{
|
||||||
/* If we fail to load the system gamemode, return our error string */
|
/* If we fail to load the system gamemode, return our error string */
|
||||||
if (_load_libgamemode() < 0) {
|
if (internal_load_libgamemode() < 0) {
|
||||||
return _client_error_string;
|
return internal_gamemode_client_error_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _REAL_gamemode_error_string();
|
return REAL_internal_gamemode_error_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,14 +173,14 @@ __attribute__((always_inline)) static inline
|
|||||||
int gamemode_request_start(void)
|
int gamemode_request_start(void)
|
||||||
{
|
{
|
||||||
/* Need to load gamemode */
|
/* Need to load gamemode */
|
||||||
if (_load_libgamemode() < 0) {
|
if (internal_load_libgamemode() < 0) {
|
||||||
#ifdef GAMEMODE_AUTO
|
#ifdef GAMEMODE_AUTO
|
||||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_REAL_gamemode_request_start() < 0) {
|
if (REAL_internal_gamemode_request_start() < 0) {
|
||||||
#ifdef GAMEMODE_AUTO
|
#ifdef GAMEMODE_AUTO
|
||||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||||
#endif
|
#endif
|
||||||
@ -196,14 +199,14 @@ __attribute__((always_inline)) static inline
|
|||||||
int gamemode_request_end(void)
|
int gamemode_request_end(void)
|
||||||
{
|
{
|
||||||
/* Need to load gamemode */
|
/* Need to load gamemode */
|
||||||
if (_load_libgamemode() < 0) {
|
if (internal_load_libgamemode() < 0) {
|
||||||
#ifdef GAMEMODE_AUTO
|
#ifdef GAMEMODE_AUTO
|
||||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_REAL_gamemode_request_end() < 0) {
|
if (REAL_internal_gamemode_request_end() < 0) {
|
||||||
#ifdef GAMEMODE_AUTO
|
#ifdef GAMEMODE_AUTO
|
||||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user