* Change variable names for characters being written
* menu_cbs_sublabel - skip some unnecessary copies
This commit is contained in:
parent
ae2465f0db
commit
9ca8e1c1c1
|
@ -152,9 +152,9 @@ int rmsgpack_write_string(intfstream_t *fd, const char *s, uint32_t len)
|
||||||
uint8_t tmp_i8 = (uint8_t)len;
|
uint8_t tmp_i8 = (uint8_t)len;
|
||||||
if (intfstream_write(fd, &tmp_i8, sizeof(uint8_t)) != -1)
|
if (intfstream_write(fd, &tmp_i8, sizeof(uint8_t)) != -1)
|
||||||
{
|
{
|
||||||
int written = sizeof(uint8_t) + sizeof(uint8_t);
|
int _len = sizeof(uint8_t) + sizeof(uint8_t);
|
||||||
if (intfstream_write(fd, s, len) != -1)
|
if (intfstream_write(fd, s, len) != -1)
|
||||||
return written + len;
|
return _len + len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,9 +166,9 @@ int rmsgpack_write_string(intfstream_t *fd, const char *s, uint32_t len)
|
||||||
uint16_t tmp_i16 = swap_if_little16(len);
|
uint16_t tmp_i16 = swap_if_little16(len);
|
||||||
if (intfstream_write(fd, &tmp_i16, sizeof(uint16_t)) != -1)
|
if (intfstream_write(fd, &tmp_i16, sizeof(uint16_t)) != -1)
|
||||||
{
|
{
|
||||||
int written = sizeof(uint8_t) + sizeof(uint16_t);
|
int _len = sizeof(uint8_t) + sizeof(uint16_t);
|
||||||
if (intfstream_write(fd, s, len) != -1)
|
if (intfstream_write(fd, s, len) != -1)
|
||||||
return written + len;
|
return _len + len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,9 +180,9 @@ int rmsgpack_write_string(intfstream_t *fd, const char *s, uint32_t len)
|
||||||
uint32_t tmp_i32 = swap_if_little32(len);
|
uint32_t tmp_i32 = swap_if_little32(len);
|
||||||
if (intfstream_write(fd, &tmp_i32, sizeof(uint32_t)) != -1)
|
if (intfstream_write(fd, &tmp_i32, sizeof(uint32_t)) != -1)
|
||||||
{
|
{
|
||||||
int written = sizeof(uint8_t) + sizeof(uint32_t);
|
int _len = sizeof(uint8_t) + sizeof(uint32_t);
|
||||||
if (intfstream_write(fd, s, len) != -1)
|
if (intfstream_write(fd, s, len) != -1)
|
||||||
return written + len;
|
return _len + len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,8 +345,8 @@ void rmsgpack_dom_value_print(struct rmsgpack_dom_value *obj)
|
||||||
int rmsgpack_dom_write(intfstream_t *fd, const struct rmsgpack_dom_value *obj)
|
int rmsgpack_dom_write(intfstream_t *fd, const struct rmsgpack_dom_value *obj)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
int written = 0;
|
int _len = 0;
|
||||||
|
|
||||||
switch (obj->type)
|
switch (obj->type)
|
||||||
{
|
{
|
||||||
|
@ -365,31 +365,31 @@ int rmsgpack_dom_write(intfstream_t *fd, const struct rmsgpack_dom_value *obj)
|
||||||
case RDT_MAP:
|
case RDT_MAP:
|
||||||
if ((rv = rmsgpack_write_map_header(fd, obj->val.map.len)) < 0)
|
if ((rv = rmsgpack_write_map_header(fd, obj->val.map.len)) < 0)
|
||||||
return rv;
|
return rv;
|
||||||
written += rv;
|
_len += rv;
|
||||||
|
|
||||||
for (i = 0; i < obj->val.map.len; i++)
|
for (i = 0; i < obj->val.map.len; i++)
|
||||||
{
|
{
|
||||||
if ((rv = rmsgpack_dom_write(fd, &obj->val.map.items[i].key)) < 0)
|
if ((rv = rmsgpack_dom_write(fd, &obj->val.map.items[i].key)) < 0)
|
||||||
return rv;
|
return rv;
|
||||||
written += rv;
|
_len += rv;
|
||||||
if ((rv = rmsgpack_dom_write(fd, &obj->val.map.items[i].value)) < 0)
|
if ((rv = rmsgpack_dom_write(fd, &obj->val.map.items[i].value)) < 0)
|
||||||
return rv;
|
return rv;
|
||||||
written += rv;
|
_len += rv;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RDT_ARRAY:
|
case RDT_ARRAY:
|
||||||
if ((rv = rmsgpack_write_array_header(fd, obj->val.array.len)) < 0)
|
if ((rv = rmsgpack_write_array_header(fd, obj->val.array.len)) < 0)
|
||||||
return rv;
|
return rv;
|
||||||
written += rv;
|
_len += rv;
|
||||||
|
|
||||||
for (i = 0; i < obj->val.array.len; i++)
|
for (i = 0; i < obj->val.array.len; i++)
|
||||||
{
|
{
|
||||||
if ((rv = rmsgpack_dom_write(fd, &obj->val.array.items[i])) < 0)
|
if ((rv = rmsgpack_dom_write(fd, &obj->val.array.items[i])) < 0)
|
||||||
return rv;
|
return rv;
|
||||||
written += rv;
|
_len += rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return written;
|
return _len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rmsgpack_read_callbacks dom_reader_callbacks = {
|
static struct rmsgpack_read_callbacks dom_reader_callbacks = {
|
||||||
|
|
|
@ -182,12 +182,12 @@ static int menu_action_sublabel_contentless_core(file_list_t *list,
|
||||||
/* Check whether runtime info is valid */
|
/* Check whether runtime info is valid */
|
||||||
if (entry->runtime.status == CONTENTLESS_CORE_RUNTIME_VALID)
|
if (entry->runtime.status == CONTENTLESS_CORE_RUNTIME_VALID)
|
||||||
{
|
{
|
||||||
size_t n = strlcat(tmp, entry->runtime.runtime_str, sizeof(tmp));
|
size_t _len = strlcat(tmp, entry->runtime.runtime_str, sizeof(tmp));
|
||||||
|
|
||||||
if (n < 64 - 1)
|
if (_len < 64 - 1)
|
||||||
{
|
{
|
||||||
tmp[n ] = '\n';
|
tmp[_len ] = '\n';
|
||||||
tmp[n+1] = '\0';
|
tmp[_len + 1] = '\0';
|
||||||
strlcat(tmp, entry->runtime.last_played_str, sizeof(tmp));
|
strlcat(tmp, entry->runtime.last_played_str, sizeof(tmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1475,7 +1475,7 @@ static int action_bind_sublabel_core_info_entry(
|
||||||
if (list && list->list[i].label && strstr(list->list[i].label, "(md5)"))
|
if (list && list->list[i].label && strstr(list->list[i].label, "(md5)"))
|
||||||
{
|
{
|
||||||
int pos = string_find_index_substring_string(list->list[i].label, "(md5)");
|
int pos = string_find_index_substring_string(list->list[i].label, "(md5)");
|
||||||
snprintf(s, len, "%s", list->list[i].label + pos);
|
strlcpy(s, list->list[i].label + pos, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1822,6 +1822,7 @@ static int action_bind_sublabel_netplay_kick_client(file_list_t *list,
|
||||||
const char *label, const char *path,
|
const char *label, const char *path,
|
||||||
char *s, size_t len)
|
char *s, size_t len)
|
||||||
{
|
{
|
||||||
|
size_t _len;
|
||||||
char buf[NAME_MAX_LENGTH];
|
char buf[NAME_MAX_LENGTH];
|
||||||
netplay_client_info_t *client;
|
netplay_client_info_t *client;
|
||||||
const char *status = NULL;
|
const char *status = NULL;
|
||||||
|
@ -1850,7 +1851,7 @@ static int action_bind_sublabel_netplay_kick_client(file_list_t *list,
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
size_t _len = strlcpy(buf, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_STATUS),
|
_len = strlcpy(buf, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_STATUS),
|
||||||
sizeof(buf) - 3);
|
sizeof(buf) - 3);
|
||||||
buf[ _len] = ':';
|
buf[ _len] = ':';
|
||||||
buf[++_len] = ' ';
|
buf[++_len] = ' ';
|
||||||
|
@ -1863,38 +1864,39 @@ static int action_bind_sublabel_netplay_kick_client(file_list_t *list,
|
||||||
|
|
||||||
if (client->devices)
|
if (client->devices)
|
||||||
{
|
{
|
||||||
int written = snprintf(buf, sizeof(buf), "%s:",
|
_len = snprintf(buf, sizeof(buf), "%s:",
|
||||||
msg_hash_to_str(MSG_NETPLAY_CLIENT_DEVICES));
|
msg_hash_to_str(MSG_NETPLAY_CLIENT_DEVICES));
|
||||||
|
|
||||||
/* Ensure that at least one device can be written. */
|
/* Ensure that at least one device can be written. */
|
||||||
if (written > 0 && written < (int)sizeof(buf) - (int)STRLEN_CONST(" 16\n"))
|
if (_len > 0 && _len < (int)sizeof(buf) - (int)STRLEN_CONST(" 16\n"))
|
||||||
{
|
{
|
||||||
uint32_t device;
|
uint32_t device;
|
||||||
char *buf_written = buf + written;
|
char *buf_written = buf + _len;
|
||||||
|
|
||||||
for (device = 0; device < (sizeof(client->devices) << 3); device++)
|
for (device = 0; device < (sizeof(client->devices) << 3); device++)
|
||||||
{
|
{
|
||||||
if (client->devices & (1 << device))
|
if (client->devices & (1 << device))
|
||||||
{
|
{
|
||||||
int tmp_written = snprintf(buf_written, sizeof(buf) - written,
|
int __len = snprintf(buf_written,
|
||||||
" %u,", (unsigned)(device + 1));
|
sizeof(buf) - _len,
|
||||||
|
" %u,", (unsigned)(device + 1));
|
||||||
|
|
||||||
/* Write nothing on error. */
|
/* Write nothing on error. */
|
||||||
if (tmp_written <= 0)
|
if (__len <= 0)
|
||||||
{
|
{
|
||||||
written = -1;
|
_len = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
written += tmp_written;
|
_len += __len;
|
||||||
if (written >= (int)sizeof(buf) - 1)
|
if (_len >= (int)sizeof(buf) - 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
buf_written += tmp_written;
|
buf_written += __len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (written > 0)
|
if (_len > 0)
|
||||||
{
|
{
|
||||||
/* Now convert the last comma into a newline. */
|
/* Now convert the last comma into a newline. */
|
||||||
buf_written = strrchr(buf, ',');
|
buf_written = strrchr(buf, ',');
|
||||||
|
@ -1913,18 +1915,14 @@ static int action_bind_sublabel_netplay_kick_client(file_list_t *list,
|
||||||
msg_hash_to_str(MSG_NETPLAY_CHAT_SUPPORTED),
|
msg_hash_to_str(MSG_NETPLAY_CHAT_SUPPORTED),
|
||||||
msg_hash_to_str((client->protocol >= 6) ?
|
msg_hash_to_str((client->protocol >= 6) ?
|
||||||
MENU_ENUM_LABEL_VALUE_YES : MENU_ENUM_LABEL_VALUE_NO));
|
MENU_ENUM_LABEL_VALUE_YES : MENU_ENUM_LABEL_VALUE_NO));
|
||||||
strlcat(s, buf, len);
|
_len = strlcat(s, buf, len);
|
||||||
|
_len += snprintf(s + _len, len - _len, "%s: %lu",
|
||||||
snprintf(buf, sizeof(buf), "%s: %lu",
|
|
||||||
msg_hash_to_str(MSG_NETPLAY_SLOWDOWNS_CAUSED),
|
msg_hash_to_str(MSG_NETPLAY_SLOWDOWNS_CAUSED),
|
||||||
(unsigned long)client->slowdowns);
|
(unsigned long)client->slowdowns);
|
||||||
strlcat(s, buf, len);
|
|
||||||
|
|
||||||
if (client->ping >= 0)
|
if (client->ping >= 0)
|
||||||
{
|
snprintf(s + _len, len - _len,
|
||||||
snprintf(buf, sizeof(buf), "\nPing: %u ms", (unsigned)client->ping);
|
"\nPing: %u ms", (unsigned)client->ping);
|
||||||
strlcat(s, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue