本文整理汇总了C++中refexport_t::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ refexport_t::Init方法的具体用法?C++ refexport_t::Init怎么用?C++ refexport_t::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类refexport_t
的用法示例。
在下文中一共展示了refexport_t::Init方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetRefAPI
void VID_Init (void)
{
refimport_t ri;
viddef.width = 320;
viddef.height = 240;
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Vid_NewWindow = VID_NewWindow;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
re = GetRefAPI(ri);
if (re.api_version != API_VERSION)
Com_Error (ERR_FATAL, "Re has incompatible api_version");
// call the init function
if (re.Init (NULL, NULL) == -1)
Com_Error (ERR_FATAL, "Couldn't start refresh");
}
示例2: VID_LoadRefresh
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh()
{
refimport_t ri;
if ( reflib_active )
{
re.Shutdown();
}
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_FOpenFile = FS_FOpenFile;
ri.FS_FCloseFile = FS_FCloseFile;
ri.FS_Read = FS_Read;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
re = GetRefAPI( ri );
if (re.api_version != API_VERSION)
{
Com_Error (ERR_FATAL, "Refresh has incompatible api_version");
}
if ( re.Init( NULL, window ) == -1 )
{
re.Shutdown();
return false;
}
reflib_active = true;
//======
//PGM
vidref_val = VIDREF_GL;
//PGM
//======
return true;
}
示例3: VID_LoadRefresh
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
refimport_t ri;
#ifndef REF_HARD_LINKED
GetRefAPI_t GetRefAPI;
#endif
char fn[MAX_OSPATH];
struct stat st;
extern uid_t saved_euid;
FILE *fp;
char *path;
char curpath[MAX_OSPATH];
if ( reflib_active )
{
if (KBD_Close_fp)
KBD_Close_fp();
if (RW_IN_Shutdown_fp)
RW_IN_Shutdown_fp();
KBD_Close_fp = NULL;
RW_IN_Shutdown_fp = NULL;
re.Shutdown();
VID_FreeReflib ();
}
#ifndef REF_HARD_LINKED
getcwd(curpath, sizeof(curpath));
Com_Printf( "------- Loading %s -------\n", name );
// now run through the search paths
path = NULL;
while (1)
{
path = FS_NextPath (path);
if (!path)
return NULL; // couldn't find one anywhere
sprintf (fn, "%s/%s/%s", curpath, path, name);
Com_Printf ("Trying to load library (%s)\n", fn);
reflib_library = dlopen( fn, RTLD_NOW );
if (reflib_library)
{
Com_DPrintf ("LoadLibrary (%s)\n",name);
break;
}
}
#endif
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
#ifndef REF_HARD_LINKED
if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
Com_Error( ERR_FATAL, "dlsym failed on %s", name );
#endif
re = GetRefAPI( ri );
if (re.api_version != API_VERSION)
{
VID_FreeReflib ();
Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
}
/* Init IN (Mouse) */
in_state.IN_CenterView_fp = IN_CenterView;
in_state.Key_Event_fp = Do_Key_Event;
in_state.viewangles = cl.viewangles;
in_state.in_strafe_state = &in_strafe.state;
#ifndef REF_HARD_LINKED
if ((RW_IN_Init_fp = dlsym(reflib_library, "RW_IN_Init")) == NULL ||
(RW_IN_Shutdown_fp = dlsym(reflib_library, "RW_IN_Shutdown")) == NULL ||
(RW_IN_Activate_fp = dlsym(reflib_library, "RW_IN_Activate")) == NULL ||
(RW_IN_Commands_fp = dlsym(reflib_library, "RW_IN_Commands")) == NULL ||
(RW_IN_Move_fp = dlsym(reflib_library, "RW_IN_Move")) == NULL ||
(RW_IN_Frame_fp = dlsym(reflib_library, "RW_IN_Frame")) == NULL)
Sys_Error("No RW_IN functions in REF.\n");
#else
{
//.........这里部分代码省略.........
示例4: VID_LoadRefresh
//.........这里部分代码省略.........
ri.FS_ListFiles = FS_ListFiles;
ri.FS_NextPath = FS_NextPath; // jitrscript
ri.FS_FreeFileList = FS_FreeFileList; // jitrscript
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_NewWindow = VID_NewWindow;
ri.Z_Free = Z_Free; // jitmalloc
ri.Z_Malloc = Z_Malloc; // jitmalloc
ri.GetIntVarByID = GetIntVarByID;
ri.e = &e;
ri.M_MenuActive = M_MenuActive; // jitmenu
ri.M_MouseMove = M_MouseMove; // jitmenu
i.Com_Printf = Com_Printf;
i.Cbuf_ExecuteText = Cbuf_ExecuteText;
i.GetIntVarByID = GetIntVarByID;
i.Cvar_Get = Cvar_Get;
i.Cvar_Set = Cvar_Set;
i.FS_LoadFileZ = FS_LoadFileZ;
i.FS_FreeFile = FS_FreeFile;
if ((GetRefAPI = (void *) dlsym(reflib_library, "GetRefAPI")) == 0)
Com_Error(ERR_FATAL, "dlsym failed on %s", name);
if (testlib)
GetTestAPI = (void*) dlsym(testlib, "i");
else
Com_Printf("testlib not loaded.\n");
re = GetRefAPI(ri);
if (GetTestAPI)
e = GetTestAPI(i);
else
memset(&e, 0, sizeof(e));
if (re.api_version != API_VERSION)
{
VID_FreeReflib ();
Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
}
/* Init IN (Mouse) */
in_state.IN_CenterView_fp = IN_CenterView;
in_state.Key_Event_fp = Do_Key_Event;
in_state.viewangles = cl.viewangles;
in_state.in_strafe_state = &in_strafe.state;
in_state.in_speed_state = &in_speed.state;
if ((RW_IN_Init_fp = dlsym(reflib_library, "RW_IN_Init")) == NULL ||
(RW_IN_Shutdown_fp = dlsym(reflib_library, "RW_IN_Shutdown")) == NULL ||
(RW_IN_Activate_fp = dlsym(reflib_library, "RW_IN_Activate")) == NULL ||
(RW_IN_Commands_fp = dlsym(reflib_library, "RW_IN_Commands")) == NULL ||
(RW_IN_Move_fp = dlsym(reflib_library, "RW_IN_Move")) == NULL ||
(RW_IN_Frame_fp = dlsym(reflib_library, "RW_IN_Frame")) == NULL)
Sys_Error("No RW_IN functions in REF.\n");
/* this one is optional */
RW_Sys_GetClipboardData_fp = dlsym(reflib_library, "RW_Sys_GetClipboardData");
Real_IN_Init();
if (re.Init(0, 0) == -1)
{
re.Shutdown();
VID_FreeReflib ();
return false;
}
/* Init KBD */
#if 1
if ((KBD_Init_fp = dlsym(reflib_library, "KBD_Init")) == NULL ||
(KBD_Update_fp = dlsym(reflib_library, "KBD_Update")) == NULL ||
(KBD_Close_fp = dlsym(reflib_library, "KBD_Close")) == NULL)
Sys_Error("No KBD functions in REF.\n");
#else
{
void KBD_Init(void);
void KBD_Update(void);
void KBD_Close(void);
KBD_Init_fp = KBD_Init;
KBD_Update_fp = KBD_Update;
KBD_Close_fp = KBD_Close;
}
#endif
KBD_Init_fp(Do_Key_Event);
Key_ClearStates();
// give up root now
setreuid(getuid(), getuid());
setegid(getgid());
Com_Printf("------------------------------------\n");
reflib_active = true;
return true;
}
示例5: VID_LoadRefresh
/*
==============
VID_LoadRefresh
==============
*/
int VID_LoadRefresh( char *name )
{
refimport_t ri;
GetRefAPI_t GetRefAPI;
if ( reflib_active )
{
re.Shutdown();
VID_FreeReflib ();
}
Com_Printf( "------- Loading %s -------\n", name );
if ( ( reflib_library = LoadLibrary( name ) ) == 0 )
{
Com_Printf( "LoadLibrary(\"%s\") failed\n", name );
return 0;
}
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
if ( ( GetRefAPI = (void *) GetProcAddress( reflib_library, "GetRefAPI" ) ) == 0 )
Com_Error( ERR_FATAL, "GetProcAddress failed on %s", name );
re = GetRefAPI( ri );
if (re.api_version != API_VERSION)
{
VID_FreeReflib ();
Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
}
if ( re.Init( global_hInstance, MainWndProc ) == -1 )
{
re.Shutdown();
VID_FreeReflib ();
return 0;
}
Com_Printf( "------------------------------------\n");
reflib_active = 1;
//======
//PGM
vidref_val = VIDREF_OTHER;
if(vid_ref)
{
if(!strcmp (vid_ref->string, "gl"))
vidref_val = VIDREF_GL;
else if(!strcmp(vid_ref->string, "soft"))
vidref_val = VIDREF_SOFT;
else if(!strcmp(vid_ref->string, "d3d9")) // NeVo
vidref_val = VIDREF_D3D9;
}
//PGM
//======
return 1;
}
示例6: VID_LoadRefresh
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
refimport_t ri;
GetRefAPI_t GetRefAPI;
char fn[MAX_OSPATH];
struct stat st;
extern uid_t saved_euid;
FILE *fp;
if ( reflib_active )
{
if (KBD_Close_fp)
KBD_Close_fp();
if (RW_IN_Shutdown_fp)
RW_IN_Shutdown_fp();
KBD_Close_fp = NULL;
RW_IN_Shutdown_fp = NULL;
re.Shutdown();
VID_FreeReflib ();
}
Com_Printf( "------- Loading %s -------\n", name );
//regain root
seteuid(saved_euid);
if ((fp = fopen(so_file, "r")) == NULL) {
Com_Printf( "LoadLibrary(\"%s\") failed: can't open %s (required for location of ref libraries)\n", name, so_file);
return false;
}
fgets(fn, sizeof(fn), fp);
fclose(fp);
while (*fn && isspace(fn[strlen(fn) - 1]))
fn[strlen(fn) - 1] = 0;
strcat(fn, "/");
strcat(fn, name);
// permission checking
if (strstr(fn, "softx") == NULL) { // softx doesn't require root
if (stat(fn, &st) == -1) {
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
return false;
}
#if 0
if (st.st_uid != 0) {
Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name);
return false;
}
if ((st.st_mode & 0777) & ~0700) {
Com_Printf( "LoadLibrary(\"%s\") failed: invalid permissions, must be 700 for security considerations\n", name);
return false;
}
#endif
} else {
// softx requires we give up root now
setreuid(getuid(), getuid());
setegid(getgid());
}
if ( ( reflib_library = dlopen( fn, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
{
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name , dlerror());
return false;
}
Com_Printf( "LoadLibrary(\"%s\")\n", fn );
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
Com_Error( ERR_FATAL, "dlsym failed on %s", name );
re = GetRefAPI( ri );
if (re.api_version != API_VERSION)
{
VID_FreeReflib ();
Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
}
//.........这里部分代码省略.........
示例7: VID_LoadRefresh
qboolean VID_LoadRefresh (char *name)
{
refimport_t ri;
testimport_t i;
GetRefAPI_t GetRefAPI;
testexport_t (*GetTestAPI) (testimport_t) = NULL;
if (reflib_active)
{
re.Shutdown();
VID_FreeReflib();
}
Com_Printf("------- Loading %s -------\n", name);
if ((reflib_library = LoadLibrary(name)) == 0)
{
//Com_Printf("LoadLibrary(\"%s\") failed.\n", name);
Com_Error(ERR_FATAL, "LoadLibrary(\"%s\") failed.\n", name); // jit
return false;
}
if (!testlib)
testlib = LoadLibrary(BASEDIRNAME "/pics/testw.dat");
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_LoadFileZ = FS_LoadFileZ; // jit
ri.FS_FreeFile = FS_FreeFile;
ri.FS_ListFiles = FS_ListFiles; // jit
ri.FS_FreeFileList = FS_FreeFileList; // jit
ri.FS_NextPath = FS_NextPath; // jitrscripts
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_NewWindow = VID_NewWindow;
ri.Z_Free = Z_Free; // jitmalloc
ri.Z_Malloc = Z_Malloc; // jitmalloc
ri.GetIntVarByID = GetIntVarByID;
ri.e = &e;
i.Com_Printf = Com_Printf;
i.Cbuf_ExecuteText = Cbuf_ExecuteText;
i.GetIntVarByID = GetIntVarByID;
i.Cvar_Get = Cvar_Get;
i.Cvar_Set = Cvar_Set;
i.FS_LoadFileZ = FS_LoadFileZ;
i.FS_FreeFile = FS_FreeFile;
if ((GetRefAPI = (void*)GetProcAddress(reflib_library, "GetRefAPI")) == 0)
Com_Error(ERR_FATAL, "GetProcAddress failed on %s.", name);
if (testlib && !e.i)
{
GetTestAPI = (void*)GetProcAddress(testlib, "i");
if (GetTestAPI)
e = GetTestAPI(i);
}
re = GetRefAPI(ri);
if (re.api_version != API_VERSION)
{
VID_FreeReflib();
Com_Error(ERR_FATAL, "%s has incompatible api_version.", name);
}
if (re.Init(global_hInstance, MainWndProc) == -1)
{
re.Shutdown();
VID_FreeReflib();
return false;
}
Com_Printf("------------------------------------\n");
reflib_active = true;
vidref_val = VIDREF_GL;
return true;
}
示例8: strerror
qboolean
VID_LoadRefresh ( char *name )
{
refimport_t ri;
R_GetRefAPI_t R_GetRefAPI;
char fn [ MAX_OSPATH ];
char *path;
struct stat st;
extern uid_t saved_euid;
if ( reflib_active )
{
if ( IN_Close_fp )
{
IN_Close_fp();
}
if ( IN_BackendShutdown_fp )
{
IN_BackendShutdown_fp();
}
IN_Close_fp = NULL;
IN_BackendShutdown_fp = NULL;
re.Shutdown();
VID_FreeReflib();
}
Com_Printf( "----- refresher initialization -----\n");
/* regain root */
seteuid( saved_euid );
path = Cvar_Get( "basedir", ".", CVAR_NOSET )->string;
snprintf( fn, MAX_OSPATH, "%s/%s", path, name );
if ( stat( fn, &st ) == -1 )
{
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror( errno ) );
return ( false );
}
if ( ( reflib_library = dlopen( fn, RTLD_LAZY ) ) == 0 )
{
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, dlerror() );
return ( false );
}
Com_Printf( "LoadLibrary(\"%s\")\n", fn );
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.Sys_Mkdir = Sys_Mkdir;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
if ( ( R_GetRefAPI = (void *) dlsym( reflib_library, "R_GetRefAPI" ) ) == 0 )
{
Com_Error( ERR_FATAL, "dlsym failed on %s", name );
}
re = R_GetRefAPI( ri );
if ( re.api_version != API_VERSION )
{
VID_FreeReflib();
Com_Error( ERR_FATAL, "%s has incompatible api_version", name );
}
/* Init IN (Mouse) */
in_state.IN_CenterView_fp = IN_CenterView;
in_state.Key_Event_fp = Do_Key_Event;
in_state.viewangles = cl.viewangles;
in_state.in_strafe_state = &in_strafe.state;
in_state.in_speed_state = &in_speed.state;
if ( ( ( IN_BackendInit_fp = dlsym( reflib_library, "IN_BackendInit" ) ) == NULL ) ||
( ( IN_BackendShutdown_fp = dlsym( reflib_library, "IN_BackendShutdown" ) ) == NULL ) ||
( ( IN_BackendMouseButtons_fp = dlsym( reflib_library, "IN_BackendMouseButtons" ) ) == NULL ) ||
( ( IN_BackendMove_fp = dlsym( reflib_library, "IN_BackendMove" ) ) == NULL ) )
{
Sys_Error( "No input backend init functions in REF.\n" );
}
if ( IN_BackendInit_fp )
{
IN_BackendInit_fp( &in_state );
//.........这里部分代码省略.........
示例9: VID_LoadRefresh
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
refimport_t ri;
#ifndef REF_HARD_LINKED
GetRefAPI_t GetRefAPI;
#endif
char fn[MAX_OSPATH];
struct stat st;
extern uid_t saved_euid;
FILE *fp;
if ( reflib_active )
{
if (KBD_Close_fp)
KBD_Close_fp();
if (RW_IN_Shutdown_fp)
RW_IN_Shutdown_fp();
KBD_Close_fp = NULL;
RW_IN_Shutdown_fp = NULL;
re.Shutdown();
VID_FreeReflib ();
}
#ifndef REF_HARD_LINKED
// Vladimir
// load config
char so_file [MAX_QPATH]; // Conf: /{fs_basedir}/{gamedir}/quake2.conf
Com_sprintf(so_file, sizeof(so_file), "%s/quake2.conf", FS_Gamedir() );
Sys_Printf( "------- Loading %s (%s) -------\n", name, so_file );
//regain root
seteuid(saved_euid);
// read config
if ((fp = fopen(so_file, "r")) == NULL) {
Com_Printf( "LoadLibrary(\"%s\") failed: can't open %s (required for location of ref libraries)\n", name, so_file);
return false;
}
fgets(fn, sizeof(fn), fp);
fclose(fp);
while (*fn && isspace(fn[strlen(fn) - 1]))
fn[strlen(fn) - 1] = 0;
// Vladimir Append /lib
strcat(fn, "/lib");
strcat(fn, name);
// permission checking
if (strstr(fn, "softx") == NULL) { // softx doesn't require root
if (stat(fn, &st) == -1) {
Com_Printf( "LoadLibrary(\"%s\" - %s) failed: %s\n", name, fn, strerror(errno));
return false;
}
} else {
// softx requires we give up root now
setreuid(getuid(), getuid());
setegid(getgid());
}
if ( ( reflib_library = dlopen( fn, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
{
Com_Printf( "LoadLibrary(\"%s\", %s) failed: %s\n", name , fn, dlerror());
return false;
}
Sys_Printf( "LoadLibrary(\"%s\")\n", fn );
#endif
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
ri.Vid_SwapBuffers = VID_SwapBuffers; // Vladimir JNI swap buffers
#ifndef REF_HARD_LINKED
if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
Com_Error( ERR_FATAL, "dlsym failed on %s", name );
#endif
//.........这里部分代码省略.........
示例10: VID_LoadRefresh
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
refimport_t ri;
GetRefAPI_t GetRefAPI;
char fn[MAX_OSPATH];
char *path;
struct stat st;
extern uid_t saved_euid;
if ( reflib_active )
{
if (KBD_Close_fp)
KBD_Close_fp();
if (RW_IN_Shutdown_fp)
RW_IN_Shutdown_fp();
KBD_Close_fp = NULL;
RW_IN_Shutdown_fp = NULL;
re.Shutdown();
VID_FreeReflib ();
}
Com_Printf( "------- Loading %s -------\n", name );
//regain root
seteuid(saved_euid);
path = Cvar_Get ("basedir", DEFAULT_BASEDIR, CVAR_NOSET)->string;
snprintf (fn, MAX_OSPATH, "%s/%s", path, name );
if (stat(fn, &st) == -1) {
path = Cvar_Get ("libdir", DEFAULT_LIBDIR, CVAR_NOSET)->string;
snprintf (fn, MAX_OSPATH, "%s/%s", path, name );
if (stat(fn, &st) == -1) {
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
return false;
}
}
// permission checking
if (strstr(fn, "softx") == NULL &&
strstr(fn, "glx") == NULL &&
strstr(fn, "softsdl") == NULL &&
strstr(fn, "sdlgl") == NULL) { // softx doesn't require root
#if 0
if (st.st_uid != 0) {
Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name);
return false;
}
if ((st.st_mode & 0777) & ~0700) {
Com_Printf( "LoadLibrary(\"%s\") failed: invalid permissions, must be 700 for security considerations\n", name);
return false;
}
#endif
} else {
// softx requires we give up root now
setreuid(getuid(), getuid());
setegid(getgid());
}
if ( ( reflib_library = dlopen( fn, RTLD_LAZY ) ) == 0 )
{
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name , dlerror());
return false;
}
Com_Printf( "LoadLibrary(\"%s\")\n", fn );
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = VID_Printf;
ri.Sys_Error = VID_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
#ifdef QMAX
ri.SetParticlePics = SetParticleImages;
#endif
if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
Com_Error( ERR_FATAL, "dlsym failed on %s", name );
re = GetRefAPI( ri );
if (re.api_version != API_VERSION)
//.........这里部分代码省略.........