Skip to content

Commit

Permalink
Cleanups, style nits, try to reduce some more strlens, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Aug 17, 2023
1 parent 0dafa3c commit f53ada6
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 113 deletions.
24 changes: 5 additions & 19 deletions frontend/drivers/platform_dos.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,9 @@ static void frontend_dos_init(void *data)
printf("Loading RetroArch. Time is @%ld...\n", (long) time(NULL));
}

static void frontend_dos_shutdown(bool unused)
{
(void)unused;
}

static int frontend_dos_get_rating(void)
{
return -1;
}
/* TODO/FIXME - implement */
static void frontend_dos_shutdown(bool unused) { }
static int frontend_dos_get_rating(void) { return -1; }

enum frontend_architecture frontend_dos_get_arch(void)
{
Expand Down Expand Up @@ -128,16 +122,8 @@ static void frontend_dos_exitspawn(char *s, size_t len, char *args)

if (dos_fork_mode == FRONTEND_FORK_NONE)
return;

switch (dos_fork_mode)
{
case FRONTEND_FORK_CORE_WITH_ARGS:
should_load_content = true;
break;
case FRONTEND_FORK_NONE:
default:
break;
}
if (dos_fork_mode == FRONTEND_FORK_CORE_WITH_ARGS)
should_load_content = true;

frontend_dos_exec(s, should_load_content);
}
Expand Down
7 changes: 3 additions & 4 deletions gfx/common/x11_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,8 @@ static void x11_set_window_pid(Display *dpy, Window win)
if (gethostname(hostname, scret + 1) == -1)
RARCH_WARN("Failed to get hostname.\n");
else
{
XChangeProperty(dpy, win, XA_WM_CLIENT_MACHINE, XA_STRING, 8,
PropModeReplace, (unsigned char *)hostname, strlen(hostname));
}
free(hostname);
}

Expand All @@ -209,10 +207,10 @@ void x11_set_window_attr(Display *dpy, Window win)
static void xdg_screensaver_inhibit(Window wnd)
{
int ret;
size_t _len;
char cmd[64];
char title[128];

cmd[0] = '\0';
title[0] = '\0';

RARCH_LOG("[X11]: Suspending screensaver (X11, xdg-screensaver).\n");
Expand All @@ -230,7 +228,8 @@ static void xdg_screensaver_inhibit(Window wnd)
8, PropModeReplace, (const unsigned char*) title, title_len);
}

snprintf(cmd, sizeof(cmd), "xdg-screensaver suspend 0x%x", (int)wnd);
_len = strlcpy(cmd, "xdg-screensaver suspend 0x", sizeof(cmd));
snprintf(cmd + _len, sizeof(cmd) - _len, "%x", (int)wnd);

if ((ret = system(cmd)) == -1)
{
Expand Down
33 changes: 18 additions & 15 deletions gfx/display_servers/dispserv_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ static Display* x11_display_server_open_display(dispserv_x11_t *dispserv)
static void x11_display_server_close_display(dispserv_x11_t *dispserv,
Display *dpy)
{
if ( !dpy
|| !dispserv
if ( !dpy
|| !dispserv
|| (dispserv->flags & DISPSERV_X11_FLAG_USING_GLOBAL_DPY)
|| dpy == g_x11_dpy)
return;
Expand All @@ -93,9 +93,10 @@ static bool x11_display_server_set_resolution(void *data,
unsigned width, unsigned height, int int_hz, float hz,
int center, int monitor_index, int xoffset, int padjust)
{
size_t _len;
int m, screen;
Window window;
XRRScreenResources
XRRScreenResources
*resources = NULL;
XRRScreenResources *res = NULL;
Display *dpy = NULL;
Expand All @@ -121,8 +122,10 @@ static bool x11_display_server_set_resolution(void *data,
dispserv->monitor_index = monitor_index;
dispserv->flags |= DISPSERV_X11_FLAG_CRT_EN;
dispserv->crt_name_id += 1;
snprintf(dispserv->crt_name, sizeof(dispserv->crt_name),
"CRT%d", dispserv->crt_name_id);
_len = strlcpy(dispserv->crt_name, "CRT", sizeof(dispserv->crt_name));
_len += snprintf(dispserv->crt_name + _len,
sizeof(dispserv->crt_name) - _len,
"%d", dispserv->crt_name_id);

strlcpy(dispserv->old_mode, dispserv->new_mode,
sizeof(dispserv->old_mode));
Expand Down Expand Up @@ -192,11 +195,11 @@ static bool x11_display_server_set_resolution(void *data,

/* Create interlaced new mode from modline variables */
if (height < 300)
crt_mode_flag = 10;
crt_mode_flag = 10;

/* Create interlaced new mode from modline variables */
if (height > 300)
crt_mode_flag = 26;
crt_mode_flag = 26;
strlcpy(dispserv->old_mode, dispserv->new_mode, sizeof(dispserv->old_mode));
/* variable for new mode */
strlcpy(dispserv->new_mode, dispserv->crt_name, sizeof(dispserv->new_mode));
Expand All @@ -205,7 +208,7 @@ static bool x11_display_server_set_resolution(void *data,
* add and delete modes */

dispserv->crt_rrmode.name = dispserv->new_mode;
dispserv->crt_rrmode.nameLength = strlen(dispserv->crt_name);
dispserv->crt_rrmode.nameLength = _len;
dispserv->crt_rrmode.dotClock = pixel_clock;
dispserv->crt_rrmode.width = width;
dispserv->crt_rrmode.hSyncStart = hfp;
Expand Down Expand Up @@ -235,7 +238,7 @@ static bool x11_display_server_set_resolution(void *data,
XRRFreeScreenResources(resources);

if (!crt_exists)
XRRCreateMode(dpy, window, &dispserv->crt_rrmode);
XRRCreateMode(dpy, window, &dispserv->crt_rrmode);

resources = XRRGetScreenResourcesCurrent(dpy, window);

Expand Down Expand Up @@ -273,7 +276,7 @@ static bool x11_display_server_set_resolution(void *data,
XSync(dpy, False);
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime,
crtc->x, crtc->y, crtc->mode, crtc->rotation,
crtc->outputs, crtc->noutput);
crtc->outputs, crtc->noutput);
XSync(dpy, False);


Expand Down Expand Up @@ -497,16 +500,16 @@ static void x11_display_server_destroy(void *data)
#ifdef HAVE_XRANDR
if (dispserv->flags & DISPSERV_X11_FLAG_CRT_EN)
{
char dmode[25];
XRRModeInfo *swoldmode = NULL;
XRRModeInfo *swdeskmode = NULL;
XRRScreenResources
XRRScreenResources
*resources = NULL;
XRRScreenResources *res = NULL;
Display *dpy = XOpenDisplay(0);
int screen = DefaultScreen(dpy);
Window window = RootWindow(dpy, screen);
bool crt_exists = false;
char dmode[25] = {0};

strlcpy(dmode, "d_mo", sizeof(dmode));

Expand Down Expand Up @@ -544,7 +547,7 @@ static void x11_display_server_destroy(void *data)


if (!crt_exists)
XRRCreateMode(dpy, window, &dispserv->crt_rrmode);
XRRCreateMode(dpy, window, &dispserv->crt_rrmode);

resources = XRRGetScreenResourcesCurrent(dpy, window);

Expand All @@ -561,7 +564,7 @@ static void x11_display_server_destroy(void *data)
{
for (i = 0; i < res->noutput; i++)
{
XRROutputInfo *outputs =
XRROutputInfo *outputs =
XRRGetOutputInfo(dpy, res, res->outputs[i]);

if (outputs->connection == RR_Connected)
Expand All @@ -586,7 +589,7 @@ static void x11_display_server_destroy(void *data)


XRRFreeCrtcInfo(crtc);
}
}
XRRFreeOutputInfo(outputs);
}

Expand Down
13 changes: 7 additions & 6 deletions gfx/drivers/d3d9hlsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,20 @@ static bool d3d9_hlsl_load_program(
struct shader_pass *pass,
const char *prog)
{
ID3DXBuffer *listing_f = NULL;
ID3DXBuffer *listing_v = NULL;
ID3DXBuffer *code_f = NULL;
ID3DXBuffer *code_v = NULL;
ID3DXBuffer *listing_f = NULL;
ID3DXBuffer *listing_v = NULL;
ID3DXBuffer *code_f = NULL;
ID3DXBuffer *code_v = NULL;
size_t prog_len = strlen(prog);

if (!d3d9x_compile_shader(prog, strlen(prog), NULL, NULL,
if (!d3d9x_compile_shader(prog, prog_len, NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f,
&pass->ftable ))
{
RARCH_ERR("Could not compile stock fragment shader..\n");
goto error;
}
if (!d3d9x_compile_shader(prog, strlen(prog), NULL, NULL,
if (!d3d9x_compile_shader(prog, prog_len, NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v,
&pass->vtable ))
{
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/orbis_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ static void *orbis_ctx_init(void *video_driver)
goto error;

#if defined(HAVE_OOSDK)
shdr_cache_dir = "/data/retroarch/temp/";
memset(&ctx_orbis->shdr_cache_config, 0, sizeof(ctx_orbis->shdr_cache_config));
shdr_cache_dir = "/data/retroarch/temp/";
ctx_orbis->shdr_cache_config.ver = 0x00010064;
snprintf(ctx_orbis->shdr_cache_config.cache_dir,
strlen(shdr_cache_dir) + 1, "%s",
Expand Down
55 changes: 27 additions & 28 deletions gfx/drivers_context/wgl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,30 @@ static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol)
}

#if (defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)) && !defined(HAVE_OPENGLES)
static bool wgl_has_extension(const char *extension, const char *extensions)
static bool wgl_has_extension(const char *ext, const char *exts)
{
const char *start = NULL;
const char *terminator = NULL;
const char *where = strchr(extension, ' ');
const char *where = strchr(ext, ' ');

if (where || *extension == '\0')
if (where || *ext == '\0')
return false;

if (!extensions)
return false;

start = extensions;

for (;;)
if (exts)
{
if (!(where = strstr(start, extension)))
break;
const char *terminator = NULL;
const char *start = exts;

terminator = where + strlen(extension);
if (where == start || *(where - 1) == ' ')
if (*terminator == ' ' || *terminator == '\0')
return true;
for (;;)
{
if (!(where = strstr(start, ext)))
break;

terminator = where + strlen(ext);
if (where == start || *(where - 1) == ' ')
if (*terminator == ' ' || *terminator == '\0')
return true;

start = terminator;
start = terminator;
}
}
return false;
}
Expand Down Expand Up @@ -267,11 +266,11 @@ void create_gl_context(HWND hwnd, bool *quit)
pcreate_context = (wglCreateContextAttribsProc)
gfx_ctx_wgl_get_proc_address("wglCreateContextAttribsARB");

/* In order to support the core info "required_hw_api"
/* In order to support the core info "required_hw_api"
* field correctly, we should try to init the highest available
* version GL context possible. This means trying successively
* version GL context possible. This means trying successively
* lower versions until it works, because GL has
* no facility for determining the highest possible
* no facility for determining the highest possible
* supported version.
*/
if (pcreate_context)
Expand Down Expand Up @@ -329,8 +328,8 @@ void create_gl_context(HWND hwnd, bool *quit)
(versions[i][0] == (int)win32_major)
&& (versions[i][1] == (int)win32_minor))
{
/* The requested version was tried and
* is not supported, go ahead and fail
/* The requested version was tried and
* is not supported, go ahead and fail
* since everything else will be lower than that. */
break;
}
Expand All @@ -348,16 +347,16 @@ void create_gl_context(HWND hwnd, bool *quit)

{
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
const char *extensions = NULL;
wglGetExtensionsStringARB =
const char *exts = NULL;
wglGetExtensionsStringARB =
(const char *(WINAPI *) (HDC))
gfx_ctx_wgl_get_proc_address("wglGetExtensionsStringARB");

if (wglGetExtensionsStringARB)
{
extensions = wglGetExtensionsStringARB(win32_hdc);
RARCH_LOG("[WGL]: Extensions: %s\n", extensions);
if (wgl_has_extension("WGL_EXT_swap_control_tear", extensions))
exts = wglGetExtensionsStringARB(win32_hdc);
RARCH_LOG("[WGL]: Extensions: %s\n", exts);
if (wgl_has_extension("WGL_EXT_swap_control_tear", exts))
{
RARCH_LOG("[WGL]: Adaptive VSync supported.\n");
wgl_flags |= WGL_FLAG_ADAPTIVE_VSYNC;
Expand Down
32 changes: 16 additions & 16 deletions gfx/drivers_context/x_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,26 @@ static const unsigned long retroarch_icon_data[] = {
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
static PFNGLXCREATECONTEXTATTRIBSARBPROC glx_create_context_attribs;

static int GLXExtensionSupported(Display *dpy, const char *extension)
static int GLXExtensionSupported(Display *dpy, const char *ext)
{
const char *extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
const char *ext_string = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
const char *client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS);
const char *pos = strstr(extensionsString, extension);
size_t pos_ext_len = strlen(extension);
const char *pos = strstr(ext_string, ext);
size_t pos_ext_len = strlen(ext);

if ( pos &&
(pos == extensionsString || pos[-1] == ' ') &&
(pos[pos_ext_len] == ' ' || pos[pos_ext_len] == '\0')
if ( pos
&& (pos == ext_string || pos[-1] == ' ')
&& (pos[pos_ext_len] == ' ' || pos[pos_ext_len] == '\0')
)
return 1;

pos = strstr(client_extensions, extension);
pos_ext_len = strlen(extension);
pos = strstr(client_extensions, ext);
pos_ext_len = strlen(ext);

if (
pos &&
(pos == extensionsString || pos[-1] == ' ') &&
(pos[pos_ext_len] == ' ' || pos[pos_ext_len] == '\0')
pos
&& (pos == ext_string || pos[-1] == ' ')
&& (pos[pos_ext_len] == ' ' || pos[pos_ext_len] == '\0')
)
return 1;

Expand Down Expand Up @@ -424,8 +424,8 @@ static void *gfx_ctx_x_init(void *data)
x->adaptive_vsync = true;
}

if (GLXExtensionSupported(g_x11_dpy, "GLX_OML_sync_control") &&
GLXExtensionSupported(g_x11_dpy, "GLX_MESA_swap_control")
if ( GLXExtensionSupported(g_x11_dpy, "GLX_OML_sync_control")
&& GLXExtensionSupported(g_x11_dpy, "GLX_MESA_swap_control")
)
x->swap_mode = 1;
#endif
Expand Down Expand Up @@ -465,7 +465,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
Atom net_wm_icon = XInternAtom(g_x11_dpy, "_NET_WM_ICON", False);
Atom cardinal = XInternAtom(g_x11_dpy, "CARDINAL", False);
settings_t *settings = config_get_ptr();
unsigned opacity = settings->uints.video_window_opacity
unsigned opacity = settings->uints.video_window_opacity
* ((unsigned)-1 / 100.0);
bool disable_composition = settings->bools.video_disable_composition;
bool show_decorations = settings->bools.video_window_show_decorations;
Expand Down Expand Up @@ -593,7 +593,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,

if (!show_decorations)
{
/* We could have just set _NET_WM_WINDOW_TYPE_DOCK instead,
/* We could have just set _NET_WM_WINDOW_TYPE_DOCK instead,
* but that removes the window from any taskbar/panel,
* so we are forced to use the old motif hints method. */
Hints hints;
Expand Down
Loading

0 comments on commit f53ada6

Please sign in to comment.