String handling cleanups

This commit is contained in:
libretroadmin 2024-12-25 19:06:04 +01:00
parent 7887719d42
commit 51e706007b
4 changed files with 241 additions and 283 deletions

View File

@ -3431,16 +3431,13 @@ static config_file_t *open_default_config_file(void)
if (!conf && has_application_data)
{
bool dir_created = false;
char basedir[DIR_MAX_LENGTH];
/* Try to create a new config file. */
fill_pathname_basedir(basedir, application_data, sizeof(basedir));
fill_pathname_join_special(conf_path, application_data,
FILE_PATH_MAIN_CONFIG, sizeof(conf_path));
dir_created = path_mkdir(basedir);
if (dir_created)
if ((path_mkdir(basedir)))
{
char skeleton_conf[PATH_MAX_LENGTH];
bool saved = false;
@ -3780,28 +3777,25 @@ static bool config_load_file(global_t *global,
}
{
char prefix[24];
size_t _len = strlcpy(prefix, "input_player", sizeof(prefix));
char prefix[64];
size_t _len = strlcpy(prefix, "input_player", sizeof(prefix));
size_t old_len = _len;
for (i = 0; i < MAX_USERS; i++)
{
size_t _len2;
char buf[64];
snprintf(prefix + _len, sizeof(prefix) - _len, "%u", i + 1);
_len = old_len;
_len += snprintf(prefix + _len, sizeof(prefix) - _len, "%u", i + 1);
_len2 = strlcpy(buf, prefix, sizeof(buf));
strlcpy(prefix + _len, "_mouse_index", sizeof(prefix) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_mouse_index[i], prefix);
strlcpy(buf + _len2, "_mouse_index", sizeof(buf) - _len2);
CONFIG_GET_INT_BASE(conf, settings, uints.input_mouse_index[i], buf);
strlcpy(prefix + _len, "_joypad_index", sizeof(prefix) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_joypad_index[i], prefix);
strlcpy(buf + _len2, "_joypad_index", sizeof(buf) - _len2);
CONFIG_GET_INT_BASE(conf, settings, uints.input_joypad_index[i], buf);
strlcpy(buf + _len2, "_analog_dpad_mode", sizeof(buf) - _len2);
CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], buf);
strlcpy(buf + _len2, "_device_reservation_type", sizeof(buf) - _len2);
CONFIG_GET_INT_BASE(conf, settings, uints.input_device_reservation_type[i], buf);
strlcpy(prefix + _len, "_analog_dpad_mode", sizeof(prefix) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], prefix);
strlcpy(prefix + _len, "_device_reservation_type", sizeof(prefix) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_device_reservation_type[i], prefix);
}
}
@ -3899,7 +3893,6 @@ static bool config_load_file(global_t *global,
{
/* Migrate from old deprecated negative value */
int wasapi_sh_buffer_length = settings->uints.audio_wasapi_sh_buffer_length;
if (wasapi_sh_buffer_length < 0)
settings->uints.audio_wasapi_sh_buffer_length = 0;
}
@ -4380,25 +4373,24 @@ bool config_load_override(void *data)
/* Create a new config file from core_path */
if (path_is_valid(core_path))
{
char tmp_path[PATH_MAX_LENGTH];
RARCH_LOG("[Overrides]: Core-specific overrides found at \"%s\".\n",
core_path);
if (should_append && !string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
{
char tmp_path[PATH_MAX_LENGTH];
size_t _len = strlcpy(tmp_path,
path_get(RARCH_PATH_CONFIG_OVERRIDE),
sizeof(tmp_path));
tmp_path[ _len] = '|';
tmp_path[++_len] = '\0';
strlcpy(tmp_path + _len, core_path, sizeof(tmp_path) - _len);
path_set(RARCH_PATH_CONFIG_OVERRIDE, tmp_path);
RARCH_LOG("[Overrides]: Core-specific overrides stacking on top of previous overrides.\n");
}
else
strlcpy(tmp_path, core_path, sizeof(tmp_path));
path_set(RARCH_PATH_CONFIG_OVERRIDE, tmp_path);
path_set(RARCH_PATH_CONFIG_OVERRIDE, core_path);
should_append = true;
show_notification = true;
@ -4410,25 +4402,23 @@ bool config_load_override(void *data)
/* Create a new config file from content_path */
if (path_is_valid(content_path))
{
char tmp_path[PATH_MAX_LENGTH];
RARCH_LOG("[Overrides]: Content dir-specific overrides found at \"%s\".\n",
content_path);
if (should_append && !string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
{
char tmp_path[PATH_MAX_LENGTH];
size_t _len = strlcpy(tmp_path,
path_get(RARCH_PATH_CONFIG_OVERRIDE),
sizeof(tmp_path));
tmp_path[ _len] = '|';
tmp_path[++_len] = '\0';
strlcpy(tmp_path + _len, content_path, sizeof(tmp_path) - _len);
path_set(RARCH_PATH_CONFIG_OVERRIDE, tmp_path);
RARCH_LOG("[Overrides]: Content dir-specific overrides stacking on top of previous overrides.\n");
}
else
strlcpy(tmp_path, content_path, sizeof(tmp_path));
path_set(RARCH_PATH_CONFIG_OVERRIDE, tmp_path);
path_set(RARCH_PATH_CONFIG_OVERRIDE, content_path);
should_append = true;
show_notification = true;
@ -4438,25 +4428,23 @@ bool config_load_override(void *data)
/* Create a new config file from game_path */
if (path_is_valid(game_path))
{
char tmp_path[PATH_MAX_LENGTH];
RARCH_LOG("[Overrides]: Game-specific overrides found at \"%s\".\n",
game_path);
if (should_append && !string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
{
char tmp_path[PATH_MAX_LENGTH];
size_t _len = strlcpy(tmp_path,
path_get(RARCH_PATH_CONFIG_OVERRIDE),
sizeof(tmp_path));
tmp_path[ _len] = '|';
tmp_path[++_len] = '\0';
strlcpy(tmp_path + _len, game_path, sizeof(tmp_path) - _len);
path_set(RARCH_PATH_CONFIG_OVERRIDE, tmp_path);
RARCH_LOG("[Overrides]: Game-specific overrides stacking on top of previous overrides.\n");
}
else
strlcpy(tmp_path, game_path, sizeof(tmp_path));
path_set(RARCH_PATH_CONFIG_OVERRIDE, tmp_path);
path_set(RARCH_PATH_CONFIG_OVERRIDE, game_path);
should_append = true;
show_notification = true;
@ -5036,14 +5024,14 @@ static void input_config_save_keybinds_user_override(config_file_t *conf,
void config_get_autoconf_profile_filename(
const char *device_name, unsigned user,
char *buf, size_t len_buf)
char *s, size_t len)
{
static const char* invalid_filename_chars[] = {
/* https://support.microsoft.com/en-us/help/905231/information-about-the-characters-that-you-cannot-use-in-site-names--fo */
"~", "#", "%", "&", "*", "{", "}", "\\", ":", "[", "]", "?", "/", "|", "\'", "\"",
NULL
};
size_t len;
size_t _len;
unsigned i;
settings_t *settings = config_st;
@ -5088,28 +5076,27 @@ void config_get_autoconf_profile_filename(
}
/* Generate autoconfig file path */
fill_pathname_join_special(buf, autoconf_dir, joypad_driver, len_buf);
fill_pathname_join_special(s, autoconf_dir, joypad_driver, len);
/* Driver specific autoconf dir may not exist, if autoconfs are not downloaded. */
if (!path_is_directory(buf))
len = strlcpy(buf, sanitised_name, len_buf);
if (!path_is_directory(s))
_len = strlcpy(s, sanitised_name, len);
else
len = fill_pathname_join_special(buf, joypad_driver, sanitised_name, len_buf);
strlcpy(buf + len, ".cfg", len_buf - len);
_len = fill_pathname_join_special(s, joypad_driver, sanitised_name, len);
strlcpy(s + _len, ".cfg", len - _len);
end:
if (sanitised_name)
free(sanitised_name);
}
/**
* config_save_autoconf_profile:
* @device_name : Input device name
* @user : Controller number to save
* Writes a controller autoconf file to disk.
**/
bool config_save_autoconf_profile(const
char *device_name, unsigned user)
bool config_save_autoconf_profile(const char *device_name, unsigned user)
{
unsigned i;
char buf[PATH_MAX_LENGTH];
@ -5922,58 +5909,59 @@ bool input_remapping_load_file(void *data, const char *path)
if (j < RARCH_FIRST_CUSTOM_BIND)
{
int btn_remap = -1;
int key_remap = -1;
char btn_ident[128];
char key_ident[128];
char ident[128];
int _remap = -1;
fill_pathname_join_delim(btn_ident, s1,
key_string, '_', sizeof(btn_ident));
fill_pathname_join_delim(key_ident, s2,
key_string, '_', sizeof(key_ident));
fill_pathname_join_delim(ident, s1,
key_string, '_', sizeof(ident));
if (config_get_int(conf, btn_ident, &btn_remap))
if (config_get_int(conf, ident, &_remap))
{
if (btn_remap == -1)
btn_remap = RARCH_UNMAPPED;
if (_remap == -1)
_remap = RARCH_UNMAPPED;
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j], btn_remap);
settings->uints.input_remap_ids[i][j], _remap);
}
if (!config_get_int(conf, key_ident, &key_remap))
key_remap = RETROK_UNKNOWN;
fill_pathname_join_delim(ident, s2,
key_string, '_', sizeof(ident));
_remap = -1;
if (!config_get_int(conf, ident, &_remap))
_remap = RETROK_UNKNOWN;
configuration_set_uint(settings,
settings->uints.input_keymapper_ids[i][j], key_remap);
settings->uints.input_keymapper_ids[i][j], _remap);
}
else
{
char stk_ident[256];
char key_ident[128];
int stk_remap = -1;
int key_remap = -1;
char ident[256];
int _remap = -1;
fill_pathname_join_delim(stk_ident, s3,
key_string, '_', sizeof(stk_ident));
fill_pathname_join_delim(ident, s3,
key_string, '_', sizeof(ident));
if (config_get_int(conf, stk_ident, &stk_remap))
if (config_get_int(conf, ident, &_remap))
{
if (stk_remap == -1)
stk_remap = RARCH_UNMAPPED;
if (_remap == -1)
_remap = RARCH_UNMAPPED;
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j], stk_remap);
settings->uints.input_remap_ids[i][j], _remap);
}
fill_pathname_join_delim(key_ident, s2,
key_string, '_', sizeof(key_ident));
fill_pathname_join_delim(ident, s2,
key_string, '_', sizeof(ident));
if (!config_get_int(conf, key_ident, &key_remap))
key_remap = RETROK_UNKNOWN;
_remap = -1;
if (!config_get_int(conf, ident, &_remap))
_remap = RETROK_UNKNOWN;
configuration_set_uint(settings,
settings->uints.input_keymapper_ids[i][j], key_remap);
settings->uints.input_keymapper_ids[i][j], _remap);
}
}
@ -6089,67 +6077,67 @@ bool input_remapping_save_file(const char *path)
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
{
char btn_ident[128];
char key_ident[128];
char _ident[128];
const char *key_string = key_strings[j];
unsigned remap_id = settings->uints.input_remap_ids[i][j];
unsigned keymap_id = settings->uints.input_keymapper_ids[i][j];
fill_pathname_join_delim(btn_ident, s1,
key_string, '_', sizeof(btn_ident));
fill_pathname_join_delim(key_ident, s2,
key_string, '_', sizeof(key_ident));
fill_pathname_join_delim(_ident, s1,
key_string, '_', sizeof(_ident));
/* Only save modified button values */
if (remap_id == j)
config_unset(conf, btn_ident);
config_unset(conf, _ident);
else
{
if (remap_id == RARCH_UNMAPPED)
config_set_int(conf, btn_ident, -1);
config_set_int(conf, _ident, -1);
else
config_set_int(conf, btn_ident,
config_set_int(conf, _ident,
settings->uints.input_remap_ids[i][j]);
}
fill_pathname_join_delim(_ident, s2,
key_string, '_', sizeof(_ident));
/* Only save non-empty keymapper values */
if (keymap_id == RETROK_UNKNOWN)
config_unset(conf, key_ident);
config_unset(conf, _ident);
else
config_set_int(conf, key_ident,
config_set_int(conf, _ident,
settings->uints.input_keymapper_ids[i][j]);
}
for (j = RARCH_FIRST_CUSTOM_BIND; j < (RARCH_FIRST_CUSTOM_BIND + 8); j++)
{
char stk_ident[128];
char key_ident[128];
char _ident[128];
const char *key_string = key_strings[j];
unsigned remap_id = settings->uints.input_remap_ids[i][j];
unsigned keymap_id = settings->uints.input_keymapper_ids[i][j];
fill_pathname_join_delim(stk_ident, s3,
key_string, '_', sizeof(stk_ident));
fill_pathname_join_delim(key_ident, s2,
key_string, '_', sizeof(key_ident));
fill_pathname_join_delim(_ident, s3,
key_string, '_', sizeof(_ident));
/* Only save modified button values */
if (remap_id == j)
config_unset(conf, stk_ident);
config_unset(conf, _ident);
else
{
if (remap_id == RARCH_UNMAPPED)
config_set_int(conf, stk_ident, -1);
config_set_int(conf, _ident, -1);
else
config_set_int(conf, stk_ident,
config_set_int(conf, _ident,
settings->uints.input_remap_ids[i][j]);
}
fill_pathname_join_delim(_ident, s2,
key_string, '_', sizeof(_ident));
/* Only save non-empty keymapper values */
if (keymap_id == RETROK_UNKNOWN)
config_unset(conf, key_ident);
config_unset(conf, _ident);
else
config_set_int(conf, key_ident,
config_set_int(conf, _ident,
settings->uints.input_keymapper_ids[i][j]);
}
@ -6230,9 +6218,9 @@ void config_load_file_salamander(void)
config_path);
if (config_get_path(config, "libretro_path",
libretro_path, sizeof(libretro_path)) &&
!string_is_empty(libretro_path) &&
!string_is_equal(libretro_path, "builtin"))
libretro_path, sizeof(libretro_path))
&& !string_is_empty(libretro_path)
&& !string_is_equal(libretro_path, "builtin"))
path_set(RARCH_PATH_CORE, libretro_path);
config_file_free(config);

View File

@ -76,11 +76,11 @@ void cdrom_lba_to_msf(unsigned lba, unsigned char *min, unsigned char *sec, unsi
if (!min || !sec || !frame)
return;
*frame = lba % 75;
lba /= 75;
*sec = lba % 60;
lba /= 60;
*min = lba;
*frame = lba % 75;
lba /= 75;
*sec = lba % 60;
lba /= 60;
*min = lba;
}
unsigned cdrom_msf_to_lba(unsigned char min, unsigned char sec, unsigned char frame)
@ -93,9 +93,9 @@ void increment_msf(unsigned char *min, unsigned char *sec, unsigned char *frame)
if (!min || !sec || !frame)
return;
*min = (*frame == 74) ? (*sec < 59 ? *min : *min + 1) : *min;
*sec = (*frame == 74) ? (*sec < 59 ? (*sec + 1) : 0) : *sec;
*frame = (*frame < 74) ? (*frame + 1) : 0;
*min = (*frame == 74) ? (*sec < 59 ? *min : *min + 1) : *min;
*sec = (*frame == 74) ? (*sec < 59 ? (*sec + 1) : 0) : *sec;
*frame = (*frame < 74) ? (*frame + 1) : 0;
}
#ifdef CDROM_DEBUG
@ -114,16 +114,14 @@ static void cdrom_print_sense_data(const unsigned char *sense, size_t len)
return;
}
key = sense[2] & 0xF;
asc = sense[12];
key = sense[2] & 0xF;
asc = sense[12];
ascq = sense[13];
printf("[CDROM] Sense Data: ");
for (i = 0; i < MIN(len, 16); i++)
{
printf("%02X ", sense[i]);
}
printf("\n");
@ -263,10 +261,10 @@ static int cdrom_send_command_win32(const libretro_vfs_implementation_file *stre
DWORD ioctl_bytes;
BOOL ioctl_rv;
#ifdef CDROM_DEBUG
clock_t t = clock();
const char *extra = " ";
static unsigned char last_min = 0;
static unsigned char last_sec = 0;
clock_t t = clock();
const char *extra = " ";
static unsigned char last_min = 0;
static unsigned char last_sec = 0;
static unsigned char last_frame = 0;
unsigned lba_cur = cdrom_msf_to_lba(last_min, last_sec, last_frame);
@ -280,7 +278,7 @@ static int cdrom_send_command_win32(const libretro_vfs_implementation_file *stre
memset(&sptd, 0, sizeof(sptd));
sptd.s.Length = sizeof(sptd.s);
sptd.s.Length = sizeof(sptd.s);
sptd.s.CdbLength = cmd_len;
switch (dir)
@ -297,11 +295,11 @@ static int cdrom_send_command_win32(const libretro_vfs_implementation_file *stre
break;
}
sptd.s.TimeOutValue = 5;
sptd.s.DataBuffer = buf;
sptd.s.TimeOutValue = 5;
sptd.s.DataBuffer = buf;
sptd.s.DataTransferLength = len;
sptd.s.SenseInfoLength = sizeof(sptd.sense);
sptd.s.SenseInfoOffset = offsetof(struct sptd_with_sense, sense);
sptd.s.SenseInfoLength = sizeof(sptd.sense);
sptd.s.SenseInfoOffset = offsetof(struct sptd_with_sense, sense);
memcpy(sptd.s.Cdb, cmd, cmd_len);
@ -321,8 +319,8 @@ static int cdrom_send_command_win32(const libretro_vfs_implementation_file *stre
fflush(stdout);
}
last_min = cmd[3];
last_sec = cmd[4];
last_min = cmd[3];
last_sec = cmd[4];
last_frame = cmd[5];
increment_msf(&last_min, &last_sec, &last_frame);
#endif
@ -337,8 +335,8 @@ static int cdrom_send_command_win32(const libretro_vfs_implementation_file *stre
#if defined(__linux__) && !defined(ANDROID)
static int cdrom_send_command_linux(const libretro_vfs_implementation_file *stream, CDROM_CMD_Direction dir, void *buf, size_t len, unsigned char *cmd, size_t cmd_len, unsigned char *sense, size_t sense_len)
{
sg_io_hdr_t sgio = {0};
int rv;
sg_io_hdr_t sgio = {0};
switch (dir)
{
@ -355,13 +353,13 @@ static int cdrom_send_command_linux(const libretro_vfs_implementation_file *stre
}
sgio.interface_id = 'S';
sgio.cmd_len = cmd_len;
sgio.cmdp = cmd;
sgio.dxferp = buf;
sgio.dxfer_len = len;
sgio.sbp = sense;
sgio.mx_sb_len = sense_len;
sgio.timeout = 5000;
sgio.cmd_len = cmd_len;
sgio.cmdp = cmd;
sgio.dxferp = buf;
sgio.dxfer_len = len;
sgio.sbp = sense;
sgio.mx_sb_len = sense_len;
sgio.timeout = 5000;
rv = ioctl(fileno(stream->fp), SG_IO, &sgio);
@ -372,7 +370,8 @@ static int cdrom_send_command_linux(const libretro_vfs_implementation_file *stre
}
#endif
static int cdrom_send_command(libretro_vfs_implementation_file *stream, CDROM_CMD_Direction dir, void *buf, size_t len, unsigned char *cmd, size_t cmd_len, size_t skip)
static int cdrom_send_command(libretro_vfs_implementation_file *stream, CDROM_CMD_Direction dir,
void *buf, size_t len, unsigned char *cmd, size_t cmd_len, size_t skip)
{
unsigned char *xfer_buf = NULL;
unsigned char *xfer_buf_pos = xfer_buf;
@ -402,7 +401,7 @@ static int cdrom_send_command(libretro_vfs_implementation_file *stream, CDROM_CM
padded_req_bytes = len + skip;
}
xfer_buf = (unsigned char*)memalign_alloc(4096, padded_req_bytes);
xfer_buf = (unsigned char*)memalign_alloc(4096, padded_req_bytes);
xfer_buf_pos = xfer_buf;
if (!xfer_buf)
@ -575,88 +574,62 @@ retry:
return rv;
}
static const char* get_profile(unsigned short profile)
static const char *cdrom_get_profile(unsigned short profile)
{
switch (profile)
{
case 2:
return "Removable disk";
break;
case 8:
return "CD-ROM";
break;
case 9:
return "CD-R";
break;
case 0xA:
return "CD-RW";
break;
case 0x10:
return "DVD-ROM";
break;
case 0x11:
return "DVD-R Sequential Recording";
break;
case 0x12:
return "DVD-RAM";
break;
case 0x13:
return "DVD-RW Restricted Overwrite";
break;
case 0x14:
return "DVD-RW Sequential recording";
break;
case 0x15:
return "DVD-R Dual Layer Sequential Recording";
break;
case 0x16:
return "DVD-R Dual Layer Jump Recording";
break;
case 0x17:
return "DVD-RW Dual Layer";
break;
case 0x1A:
return "DVD+RW";
break;
case 0x1B:
return "DVD+R";
break;
case 0x2A:
return "DVD+RW Dual Layer";
break;
case 0x2B:
return "DVD+R Dual Layer";
break;
case 0x40:
return "BD-ROM";
break;
case 0x41:
return "BD-R SRM";
break;
case 0x42:
return "BD-R RRM";
break;
case 0x43:
return "BD-RE";
break;
case 0x50:
return "HD DVD-ROM";
break;
case 0x51:
return "HD DVD-R";
break;
case 0x52:
return "HD DVD-RAM";
break;
case 0x53:
return "HD DVD-RW";
break;
case 0x58:
return "HD DVD-R Dual Layer";
break;
case 0x5A:
return "HD DVD-RW Dual Layer";
break;
default:
break;
}
@ -664,6 +637,7 @@ static const char* get_profile(unsigned short profile)
return "Unknown";
}
/* TODO/FIXME - sense never used here? */
int cdrom_get_sense(libretro_vfs_implementation_file *stream, unsigned char *sense, size_t len)
{
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x3, 0, 0, 0, 0xFC, 0};
@ -821,7 +795,7 @@ void cdrom_get_current_config_profiles(libretro_vfs_implementation_file *stream)
{
unsigned short profile = (buf[8 + (4 * (i + 1))] << 8) | buf[8 + (4 * (i + 1)) + 1];
printf("[CDROM] Profile Number: %04X (%s) ", profile, get_profile(profile));
printf("[CDROM] Profile Number: %04X (%s) ", profile, cdrom_get_profile(profile));
if (buf[8 + (4 * (i + 1)) + 2] & 1)
printf("(current)\n");
@ -893,7 +867,7 @@ void cdrom_get_current_config_core(libretro_vfs_implementation_file *stream)
printf("[CDROM] Physical Interface Standard: %u (%s)\n", intf_std, intf_std_name);
}
int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *buf, size_t len)
int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *s, size_t len)
{
/* MMC Command: READ TOC/PMA/ATIP */
unsigned char cdb[] = {0x43, 0x2, 0x2, 0, 0, 0, 0x1, 0x9, 0x30, 0};
@ -905,18 +879,18 @@ int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *buf
#endif
int rv;
if (!buf)
if (!s)
return 1;
rv = cdrom_send_command(stream, DIRECTION_IN, buf, len, cdb, sizeof(cdb), 0);
rv = cdrom_send_command(stream, DIRECTION_IN, s, len, cdb, sizeof(cdb), 0);
if (rv)
return 1;
#ifdef CDROM_DEBUG
data_len = buf[0] << 8 | buf[1];
first_session = buf[2];
last_session = buf[3];
data_len = s[0] << 8 | s[1];
first_session = s[2];
last_session = s[3];
printf("[CDROM] Data Length: %d\n", data_len);
printf("[CDROM] First Session: %d\n", first_session);
@ -924,14 +898,16 @@ int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *buf
for (i = 0; i < (data_len - 2) / 11; i++)
{
unsigned char session_num = buf[4 + (i * 11) + 0];
unsigned char adr = (buf[4 + (i * 11) + 1] >> 4) & 0xF;
/*unsigned char control = buf[4 + (i * 11) + 1] & 0xF;*/
unsigned char tno = buf[4 + (i * 11) + 2];
unsigned char point = buf[4 + (i * 11) + 3];
unsigned char pmin = buf[4 + (i * 11) + 8];
unsigned char psec = buf[4 + (i * 11) + 9];
unsigned char pframe = buf[4 + (i * 11) + 10];
unsigned char session_num = s[4 + (i * 11) + 0];
unsigned char adr = (s[4 + (i * 11) + 1] >> 4) & 0xF;
#if 0
unsigned char control = s[4 + (i * 11) + 1] & 0xF;
#endif
unsigned char tno = s[4 + (i * 11) + 2];
unsigned char point = s[4 + (i * 11) + 3];
unsigned char pmin = s[4 + (i * 11) + 8];
unsigned char psec = s[4 + (i * 11) + 9];
unsigned char pframe = s[4 + (i * 11) + 10];
/*printf("i %d control %d adr %d tno %d point %d: ", i, control, adr, tno, point);*/
/* why is control always 0? */
@ -978,9 +954,8 @@ static int cdrom_read_track_info(libretro_vfs_implementation_file *stream, unsig
cdb[5] = track;
rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb, sizeof(cdb), 0);
if (rv)
if ((rv = cdrom_send_command(stream, DIRECTION_IN, buf,
sizeof(buf), cdb, sizeof(cdb), 0)))
return 1;
memcpy(&lba, buf + 8, 4);
@ -1159,7 +1134,7 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
}
/* needs 32 bytes for full vendor, product and version */
int cdrom_get_inquiry(libretro_vfs_implementation_file *stream, char *model, int len, bool *is_cdrom)
int cdrom_get_inquiry(libretro_vfs_implementation_file *stream, char *s, size_t len, bool *is_cdrom)
{
/* MMC Command: INQUIRY */
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x12, 0, 0, 0, 0xff, 0};
@ -1170,22 +1145,17 @@ int cdrom_get_inquiry(libretro_vfs_implementation_file *stream, char *model, int
if (rv)
return 1;
if (model && len >= 32)
if (s && len >= 32)
{
memset(model, 0, len);
memset(s, 0, len);
/* vendor */
memcpy(model, buf + 8, 8);
model[8] = ' ';
memcpy(s, buf + 8, 8);
s[8] = ' ';
/* product */
memcpy(model + 9, buf + 16, 16);
model[25] = ' ';
memcpy(s + 9, buf + 16, 16);
s[25] = ' ';
/* version */
memcpy(model + 26, buf + 32, 4);
memcpy(s + 26, buf + 32, 4);
}
cdrom = (buf[0] == 5);
@ -1194,7 +1164,7 @@ int cdrom_get_inquiry(libretro_vfs_implementation_file *stream, char *model, int
*is_cdrom = true;
#ifdef CDROM_DEBUG
printf("[CDROM] Device Model: %s (is CD-ROM? %s)\n", model, (cdrom ? "yes" : "no"));
printf("[CDROM] Device Model: %s (is CD-ROM? %s)\n", s, (cdrom ? "yes" : "no"));
#endif
return 0;
}
@ -1402,7 +1372,7 @@ struct string_list* cdrom_get_available_drives(void)
struct string_list mods = {0};
string_list_initialize(&mods);
if (string_split_noalloc(&mods, buf, "\n"))
{
for (i = 0; i < (int)mods.size; i++)
@ -1686,46 +1656,52 @@ bool cdrom_has_atip(libretro_vfs_implementation_file *stream)
return true;
}
void cdrom_device_fillpath(char *path, size_t len, char drive, unsigned char track, bool is_cue)
size_t cdrom_device_fillpath(char *s, size_t len, char drive, unsigned char track, bool is_cue)
{
if (!path || len == 0)
return;
if (is_cue)
if (s && len > 0)
{
if (is_cue)
{
#ifdef _WIN32
size_t pos = strlcpy(path, "cdrom://", len);
if (len > pos)
path[pos++] = drive;
pos = strlcat(path, ":/drive.cue", len);
size_t _len = strlcpy(s, "cdrom://", len);
if (len > _len)
s[_len++] = drive;
_len += strlcpy(s + _len, ":/drive.cue", len - _len);
return _len;
#else
#ifdef __linux__
size_t pos = strlcpy(path, "cdrom://drive", len);
if (len > pos + 1)
{
path[pos++] = drive;
path[pos] = '\0';
size_t _len = strlcpy(s, "cdrom://drive", len);
if (len > _len + 1)
{
s[_len++] = drive;
s[_len] = '\0';
}
_len += strlcpy(s + _len, ".cue", len - _len);
return _len;
#endif
#endif
}
pos = strlcat(path, ".cue", len);
#endif
#endif
}
else
{
else
{
#ifdef _WIN32
size_t pos = strlcpy(path, "cdrom://", len);
if (len > pos + 1)
{
path[pos++] = drive;
path[pos] = '\0';
}
pos += snprintf(path + pos, len - pos, ":/drive-track%02d.bin", track);
size_t _len = strlcpy(s, "cdrom://", len);
if (len > _len + 1)
{
s[_len++] = drive;
s[_len] = '\0';
}
_len += snprintf(s + _len, len - _len, ":/drive-track%02d.bin", track);
return _len;
#else
#ifdef __linux__
size_t pos = strlcpy(path, "cdrom://drive", len);
if (len > pos)
path[pos++] = drive;
pos += snprintf(path + pos, len - pos, "-track%02d.bin", track);
size_t _len = strlcpy(s, "cdrom://drive", len);
if (len > _len)
s[_len++] = drive;
_len += snprintf(s + _len, len - _len, "-track%02d.bin", track);
return _len;
#endif
#endif
}
}
return 0;
}

View File

@ -79,7 +79,7 @@ int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *buf
int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, size_t *out_len, char cdrom_drive, unsigned char *num_tracks, cdrom_toc_t *toc);
/* needs 32 bytes for full vendor, product and version */
int cdrom_get_inquiry(libretro_vfs_implementation_file *stream, char *model, int len, bool *is_cdrom);
int cdrom_get_inquiry(libretro_vfs_implementation_file *stream, char *s, size_t len, bool *is_cdrom);
int cdrom_read(libretro_vfs_implementation_file *stream, cdrom_group_timeouts_t *timeouts, unsigned char min, unsigned char sec, unsigned char frame, void *s, size_t len, size_t skip);
@ -118,7 +118,7 @@ bool cdrom_get_timeouts(libretro_vfs_implementation_file *stream, cdrom_group_ti
bool cdrom_has_atip(libretro_vfs_implementation_file *stream);
void cdrom_device_fillpath(char *path, size_t len, char drive, unsigned char track, bool is_cue);
size_t cdrom_device_fillpath(char *s, size_t len, char drive, unsigned char track, bool is_cue);
RETRO_END_DECLS

View File

@ -536,13 +536,12 @@ static enum msg_hash_enums action_ok_dl_to_enum(unsigned lbl)
static void action_ok_get_file_browser_start_path(
const char *current_path, const char *default_path,
char *start_path, size_t start_path_len,
bool set_pending)
char *s, size_t len, bool set_pending)
{
const char *pending_selection = NULL;
bool current_path_valid = false;
if (!start_path || (start_path_len < 1))
if (!s || (len < 1))
return;
/* Parse current path */
@ -550,16 +549,13 @@ static void action_ok_get_file_browser_start_path(
{
/* Start path is the parent directory of
* the current path */
fill_pathname_parent_dir(start_path, current_path,
start_path_len);
fill_pathname_parent_dir(s, current_path, len);
/* 'Pending selection' is the basename of
* the current path - either a file name
* or a directory name */
pending_selection = path_basename(current_path);
/* Check if current path is valid */
if ( path_is_directory(start_path)
if ( path_is_directory(s)
&& !string_is_empty(pending_selection))
current_path_valid = true;
}
@ -570,11 +566,11 @@ static void action_ok_get_file_browser_start_path(
if ( string_is_empty(default_path)
|| !path_is_directory(default_path))
{
start_path[0] = '\0';
s[0] = '\0';
return;
}
strlcpy(start_path, default_path, start_path_len);
strlcpy(s, default_path, len);
return;
}
/* Current path is valid - set pending selection,
@ -2562,7 +2558,7 @@ static int action_ok_file_load(const char *path,
{
case FILE_TYPE_IN_CARCHIVE:
fill_pathname_join_delim(full_path_new, menu_path_new, path,
'#',sizeof(full_path_new));
'#', sizeof(full_path_new));
break;
default:
fill_pathname_join_special(full_path_new, menu_path_new, path,
@ -2991,14 +2987,14 @@ static int action_ok_load_cdrom(const char *path,
if (sysinfo && !string_is_empty(sysinfo->library_name))
{
char cdrom_path[256] = {0};
char cdrom_path[256];
cdrom_device_fillpath(cdrom_path, sizeof(cdrom_path), label[0], 0, true);
RARCH_LOG("[CDROM]: Loading disc from path: %s\n", cdrom_path);
path_clear(RARCH_PATH_CONTENT);
path_set(RARCH_PATH_CONTENT, cdrom_path);
if (!string_is_empty(cdrom_path))
path_set(RARCH_PATH_CONTENT, cdrom_path);
#if defined(HAVE_DYNAMIC)
{
@ -3271,7 +3267,7 @@ static void menu_input_st_string_cb_rename_entry(void *userdata,
if (!string_is_empty(label))
{
struct playlist_entry entry = {0};
struct playlist_entry entry = {0};
struct menu_state *menu_st = menu_state_get_ptr();
unsigned idx = menu_st->input_dialog_kb_idx;
@ -3582,7 +3578,6 @@ static int action_ok_shader_preset_remove_game(const char *path,
}
#endif
static int action_ok_video_filter_remove(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
@ -3596,8 +3591,8 @@ static int action_ok_video_filter_remove(const char *path,
settings->paths.path_softfilter_plugin[0] = '\0';
command_event(CMD_EVENT_REINIT, NULL);
/* Refresh menu */
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
| MENU_ST_FLAG_PREVENT_POPULATE;
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
| MENU_ST_FLAG_PREVENT_POPULATE;
}
return 0;
}
@ -3618,8 +3613,8 @@ static int action_ok_audio_dsp_plugin_remove(const char *path,
command_event(CMD_EVENT_DSP_FILTER_INIT, NULL);
/* Refresh menu */
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
| MENU_ST_FLAG_PREVENT_POPULATE;
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
| MENU_ST_FLAG_PREVENT_POPULATE;
}
return 0;
@ -3705,7 +3700,7 @@ static int generic_action_ok_remap_file_operation(const char *path,
return -1;
if ( sort_remaps_by_controller
&& input_device_name != NULL
&& (input_device_name != NULL)
&& !string_is_empty(input_device_name))
{
/* Ensure directory does not contain special chars */
@ -3936,11 +3931,11 @@ static int action_ok_remap_file_reset(const char *path,
static int action_ok_remap_file_flush(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
char msg[128];
runloop_state_t *runloop_st = runloop_state_get_ptr();
const char *path_remapfile = runloop_st->name.remapfile;
const char *remapfile = NULL;
bool success = false;
char msg[128];
msg[0] = '\0';
@ -4179,9 +4174,10 @@ static int action_ok_deferred_list_stub(const char *path,
static int action_ok_set_switch_cpu_profile(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
size_t _len;
char command[PATH_MAX_LENGTH] = {0};
unsigned profile_clock = SWITCH_CPU_SPEEDS_VALUES[entry_idx];
settings_t *settings = config_get_ptr();
unsigned profile_clock = SWITCH_CPU_SPEEDS_VALUES[entry_idx];
settings_t *settings = config_get_ptr();
settings->uints.libnx_overclock = entry_idx;
@ -4195,8 +4191,8 @@ static int action_ok_set_switch_cpu_profile(const char *path,
clkrstCloseSession(&session);
}
/* TODO/FIXME - localize */
snprintf(command, sizeof(command),
"Current Clock set to %i", profile_clock);
_len = strlcpy(command, "Current clock set to", sizeof(command));
snprintf(command + _len, sizeof(command) - _len, "%i", profile_clock);
runloop_msg_queue_push(command, 1, 90, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4287,6 +4283,7 @@ static int action_ok_audio_run(const char *path,
int action_ok_core_option_dropdown_list(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
size_t _len;
char option_path_str[64];
char option_lbl_str[64];
core_option_manager_t *coreopts = NULL;
@ -4295,7 +4292,6 @@ int action_ok_core_option_dropdown_list(const char *path,
const char *value_label_1 = NULL;
size_t option_index = type - MENU_SETTINGS_CORE_OPTION_START;
option_path_str[0] = '\0';
option_lbl_str[0] = '\0';
/* Boolean options are toggled directly,
@ -4343,8 +4339,11 @@ int action_ok_core_option_dropdown_list(const char *path,
push_dropdown_list:
/* If this option is not a boolean toggle,
* push drop-down list */
snprintf(option_path_str, sizeof(option_path_str),
"core_option_%d", (int)option_index);
_len = strlcpy(option_path_str, "core_option_",
sizeof(option_path_str));
snprintf(option_path_str + _len,
sizeof(option_path_str) - _len,
"%d", (int)option_index);
snprintf(option_lbl_str, sizeof(option_lbl_str),
"%d", type);
@ -4437,7 +4436,7 @@ static int action_ok_cheat_add_top(const char *path,
memcpy(&cheat_manager_state.cheats[0], &tmp, sizeof(struct item_cheat));
strlcpy(msg, msg_hash_to_str(MSG_CHEAT_ADD_TOP_SUCCESS), sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4458,7 +4457,7 @@ static int action_ok_cheat_add_bottom(const char *path,
strlcpy(msg,
msg_hash_to_str(MSG_CHEAT_ADD_BOTTOM_SUCCESS), sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4479,7 +4478,7 @@ static int action_ok_cheat_delete_all(const char *path,
strlcpy(msg, msg_hash_to_str(MSG_CHEAT_DELETE_ALL_SUCCESS),
sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4514,7 +4513,7 @@ static int action_ok_cheat_add_new_after(const char *path,
| MENU_ST_FLAG_PREVENT_POPULATE;
strlcpy(msg, msg_hash_to_str(MSG_CHEAT_ADD_AFTER_SUCCESS), sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4550,7 +4549,7 @@ static int action_ok_cheat_add_new_before(const char *path,
| MENU_ST_FLAG_PREVENT_POPULATE;
strlcpy(msg, msg_hash_to_str(MSG_CHEAT_ADD_BEFORE_SUCCESS), sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4587,7 +4586,7 @@ static int action_ok_cheat_copy_before(const char *path,
| MENU_ST_FLAG_PREVENT_POPULATE;
strlcpy(msg, msg_hash_to_str(MSG_CHEAT_COPY_BEFORE_SUCCESS), sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4624,7 +4623,7 @@ static int action_ok_cheat_copy_after(const char *path,
| MENU_ST_FLAG_PREVENT_POPULATE;
strlcpy(msg, msg_hash_to_str(MSG_CHEAT_COPY_AFTER_SUCCESS), sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4665,7 +4664,7 @@ static int action_ok_cheat_delete(const char *path,
cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO);
strlcpy(msg, msg_hash_to_str(MSG_CHEAT_DELETE_SUCCESS), sizeof(msg));
msg[sizeof(msg) - 1] = 0;
msg[sizeof(msg) - 1] = 0; /* TODO/FIXME - is this necessary? */
runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
@ -4711,10 +4710,8 @@ static int action_ok_file_load_current_core(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
menu_handle_t *menu = menu_state_get_ptr()->driver_data;
if (!menu)
return -1;
return default_action_ok_load_content_with_core_from_menu(
menu->detect_content_path, CORE_TYPE_PLAIN);
}
@ -5524,15 +5521,13 @@ static int action_ok_switch_installed_cores_pfd(const char *path,
static int action_ok_sideload_core(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
char backup_path[PATH_MAX_LENGTH];
const char *menu_path = NULL;
const char *core_file = path;
bool core_loaded = false;
menu_handle_t *menu = menu_state_get_ptr()->driver_data;
settings_t *settings = config_get_ptr();
const char *dir_libretro = settings->paths.directory_libretro;
if (string_is_empty(core_file) || !menu)
if (string_is_empty(path) || !menu)
return -1;
/* Get path of source (core 'backup') file */
@ -5540,13 +5535,14 @@ static int action_ok_sideload_core(const char *path,
&menu_path, NULL, NULL, NULL, NULL);
if (!string_is_empty(menu_path))
{
char backup_path[PATH_MAX_LENGTH];
fill_pathname_join_special(
backup_path, menu_path, core_file, sizeof(backup_path));
backup_path, menu_path, path, sizeof(backup_path));
task_push_core_restore(backup_path, dir_libretro, &core_loaded);
}
else
strlcpy(backup_path, core_file, sizeof(backup_path));
/* Push core 'restore' task */
task_push_core_restore(backup_path, dir_libretro, &core_loaded);
task_push_core_restore(path, dir_libretro, &core_loaded);
/* Flush stack
* > Since the 'sideload core' option is present
@ -5876,13 +5872,13 @@ static int action_ok_add_entry_to_playlist(const char *path,
if(!label)
return 0;
/*
*
* path = menu entry select. use this to identify the menu item to add the content to
* entry->path = The file path of the currently selected content
* [INFO] [playlist] = Add to Favorites
* [INFO] [content_path] = C:\roms\Arcade - Mame 2003 Plus\aburner2.zip
*/
/*
*
* path = menu entry select. use this to identify the menu item to add the content to
* entry->path = The file path of the currently selected content
* [INFO] [playlist] = Add to Favorites
* [INFO] [content_path] = C:\roms\Arcade - Mame 2003 Plus\aburner2.zip
*/
/* Read current playlist parameters */
playlist_get_index(playlist_curr, menu->rpl_entry_selection_ptr, &entry);
@ -6522,10 +6518,8 @@ static int action_ok_netplay_connect_room(const char *path, const char *label,
retroarch_menu_running_finished(false);
}
else
{
task_push_netplay_crc_scan(room->gamecrc, room->gamename,
room->subsystem_name, room->corename, hostname);
}
return 0;
}
@ -7119,8 +7113,8 @@ static int action_ok_push_dropdown_item_playlist_default_core(
return -1;
/* Handle N/A or empty path input */
if (string_is_empty(core_name) ||
string_is_equal(core_name, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)))
if ( string_is_empty(core_name)
|| string_is_equal(core_name, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)))
{
playlist_set_default_core_path(playlist, FILE_PATH_DETECT);
playlist_set_default_core_name(playlist, FILE_PATH_DETECT);