Skip to content

Commit

Permalink
Conventionalize len variables:
Browse files Browse the repository at this point in the history
* In function arguments, use 'size_t len'
* Inside the function, use '_len'
* If you need a seciondary len variable inside the function, use '__len'
  • Loading branch information
LibretroAdmin committed Dec 27, 2024
1 parent bc819bb commit ed58e4a
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 195 deletions.
4 changes: 2 additions & 2 deletions gfx/widgets/gfx_widget_load_content_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ bool gfx_widget_start_load_content_animation(void)
* > Use db_name, if available */
if (has_db_name)
{
size_t len = fill_pathname(state->icon_file,
fill_pathname(state->icon_file,
state->system_name,
".png",
sizeof(state->icon_file));
Expand Down Expand Up @@ -476,7 +476,7 @@ bool gfx_widget_start_load_content_animation(void)
if ( !string_is_empty(core_db_name)
&& !string_is_equal(core_db_name, state->system_name))
{
size_t len = fill_pathname(state->icon_file,
fill_pathname(state->icon_file,
core_db_name,
".png",
sizeof(state->icon_file));
Expand Down
42 changes: 21 additions & 21 deletions libretro-common/file/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static void config_file_get_realpath(char *s, size_t len,
}

static void config_file_add_sub_conf(config_file_t *conf, char *path,
char *real_path, size_t len, config_file_cb_t *cb)
char *s, size_t len, config_file_cb_t *cb)
{
struct config_include_list *head = conf->includes;
struct config_include_list *node = (struct config_include_list*)
Expand All @@ -403,13 +403,13 @@ static void config_file_add_sub_conf(config_file_t *conf, char *path,
conf->includes = node;
}

config_file_get_realpath(real_path, len, path,
config_file_get_realpath(s, len, path,
conf->path);
}

size_t config_file_add_reference(config_file_t *conf, char *path)
{
size_t len;
size_t _len;
/* It is expected that the conf has it's path already set */
char short_path[NAME_MAX_LENGTH];
if (!conf->references)
Expand All @@ -418,9 +418,9 @@ size_t config_file_add_reference(config_file_t *conf, char *path)
conf->references->next = NULL;
conf->references->path = NULL;
}
len = fill_pathname_abbreviated_or_relative(short_path, conf->path, path, sizeof(short_path));
_len = fill_pathname_abbreviated_or_relative(short_path, conf->path, path, sizeof(short_path));
path_linked_list_add_path(conf->references, short_path);
return len;
return _len;
}

static int config_file_load_internal(
Expand Down Expand Up @@ -1338,62 +1338,62 @@ size_t config_set_double(config_file_t *conf, const char *key, double val)
{
char buf[320];
#ifdef __cplusplus
size_t len = snprintf(buf, sizeof(buf), "%f", (float)val);
size_t _len = snprintf(buf, sizeof(buf), "%f", (float)val);
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
size_t len = snprintf(buf, sizeof(buf), "%lf", val);
size_t _len = snprintf(buf, sizeof(buf), "%lf", val);
#else
size_t len = snprintf(buf, sizeof(buf), "%f", (float)val);
size_t _len = snprintf(buf, sizeof(buf), "%f", (float)val);
#endif
config_set_string(conf, key, buf);
return len;
return _len;
}

size_t config_set_float(config_file_t *conf, const char *key, float val)
{
char buf[64];
size_t len = snprintf(buf, sizeof(buf), "%f", val);
size_t _len = snprintf(buf, sizeof(buf), "%f", val);
config_set_string(conf, key, buf);
return len;
return _len;
}

size_t config_set_int(config_file_t *conf, const char *key, int val)
{
char buf[16];
size_t len = snprintf(buf, sizeof(buf), "%d", val);
size_t _len = snprintf(buf, sizeof(buf), "%d", val);
config_set_string(conf, key, buf);
return len;
return _len;
}

size_t config_set_uint(config_file_t *conf, const char *key, unsigned int val)
{
char buf[16];
size_t len = snprintf(buf, sizeof(buf), "%u", val);
size_t _len = snprintf(buf, sizeof(buf), "%u", val);
config_set_string(conf, key, buf);
return len;
return _len;
}

size_t config_set_hex(config_file_t *conf, const char *key, unsigned val)
{
char buf[16];
size_t len = snprintf(buf, sizeof(buf), "%x", val);
size_t _len = snprintf(buf, sizeof(buf), "%x", val);
config_set_string(conf, key, buf);
return len;
return _len;
}

size_t config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
{
char buf[32];
size_t len = snprintf(buf, sizeof(buf), "%" PRIu64, val);
size_t _len = snprintf(buf, sizeof(buf), "%" PRIu64, val);
config_set_string(conf, key, buf);
return len;
return _len;
}

size_t config_set_char(config_file_t *conf, const char *key, char val)
{
char buf[2];
size_t len = snprintf(buf, sizeof(buf), "%c", val);
size_t _len = snprintf(buf, sizeof(buf), "%c", val);
config_set_string(conf, key, buf);
return len;
return _len;
}

/**
Expand Down
27 changes: 13 additions & 14 deletions libretro-common/net/net_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct http_connection_t
**/
void net_http_urlencode(char **dest, const char *source)
{
static const char urlencode_lut[256] =
static const char urlencode_lut[256] =
{
0, /* 0 */
0, /* 1 */
Expand Down Expand Up @@ -360,9 +360,9 @@ void net_http_urlencode(char **dest, const char *source)
};

/* Assume every character will be encoded, so we need 3 times the space. */
size_t len = strlen(source) * 3 + 1;
size_t count = len;
char *enc = (char*)calloc(1, len);
size_t _len = strlen(source) * 3 + 1;
size_t count = _len;
char *enc = (char*)calloc(1, _len);
*dest = enc;

for (; *source; source++)
Expand All @@ -381,16 +381,15 @@ void net_http_urlencode(char **dest, const char *source)
while (*++enc);
}

(*dest)[len - 1] = '\0';
(*dest)[_len - 1] = '\0';
}

/**
* net_http_urlencode_full:
*
* Re-encode a full URL
**/
void net_http_urlencode_full(char *dest,
const char *source, size_t size)
void net_http_urlencode_full(char *s, const char *source, size_t len)
{
size_t buf_pos;
size_t tmp_len;
Expand Down Expand Up @@ -418,10 +417,10 @@ void net_http_urlencode_full(char *dest,

tmp = NULL;
net_http_urlencode(&tmp, url_path);
buf_pos = strlcpy(dest, url_domain, size);
dest[ buf_pos] = '/';
dest[++buf_pos] = '\0';
strlcpy(dest + buf_pos, tmp, size - buf_pos);
buf_pos = strlcpy(s, url_domain, len);
s[ buf_pos] = '/';
s[++buf_pos] = '\0';
strlcpy(s + buf_pos, tmp, len - buf_pos);
free(tmp);
}

Expand All @@ -443,7 +442,7 @@ static int net_http_new_socket(struct http_connection_t *conn)
goto done;
}

/* TODO: Properly figure out what's going wrong when the newer
/* TODO: Properly figure out what's going wrong when the newer
timeout/poll code interacts with mbed and winsock
https://github.com/libretro/RetroArch/issues/14742 */

Expand Down Expand Up @@ -994,7 +993,7 @@ bool net_http_update(struct http_t *state, size_t* progress, size_t* total)
state->error = true;
goto error;
}
state->status = (int)strtoul(state->data
state->status = (int)strtoul(state->data
+ STRLEN_CONST("HTTP/1.1 "), NULL, 10);
state->part = P_HEADER;
}
Expand Down Expand Up @@ -1191,7 +1190,7 @@ bool net_http_update(struct http_t *state, size_t* progress, size_t* total)
* Report HTTP status. 200, 404, or whatever.
*
* Leaf function.
*
*
* @return HTTP status code.
**/
int net_http_status(struct http_t *state)
Expand Down
12 changes: 6 additions & 6 deletions libretro-common/string/stdstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ char *string_trim_whitespace_left(char *const s)
{
if (s && *s)
{
size_t len = strlen(s);
size_t _len = strlen(s);
char *current = s;

while (*current && ISSPACE((unsigned char)*current))
{
++current;
--len;
--_len;
}

if (s != current)
memmove(s, current, len + 1);
memmove(s, current, _len + 1);
}

return s;
Expand All @@ -159,13 +159,13 @@ char *string_trim_whitespace_right(char *const s)
{
if (s && *s)
{
size_t len = strlen(s);
char *current = s + len - 1;
size_t _len = strlen(s);
char *current = s + _len - 1;

while (current != s && ISSPACE((unsigned char)*current))
{
--current;
--len;
--_len;
}

current[ISSPACE((unsigned char)*current) ? 0 : 1] = '\0';
Expand Down
34 changes: 17 additions & 17 deletions libretro-common/vfs/vfs_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,18 +617,18 @@ int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream)
return 0;
}

int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, int64_t length)
int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, int64_t len)
{
#ifdef _WIN32
if (stream && _chsize(_fileno(stream->fp), length) == 0)
if (stream && _chsize(_fileno(stream->fp), len) == 0)
{
stream->size = length;
stream->size = len;
return 0;
}
#elif !defined(VITA) && !defined(PSP) && !defined(PS2) && !defined(ORBIS) && (!defined(SWITCH) || defined(HAVE_LIBNX))
if (stream && ftruncate(fileno(stream->fp), (off_t)length) == 0)
if (stream && ftruncate(fileno(stream->fp), (off_t)len) == 0)
{
stream->size = length;
stream->size = len;
return 0;
}
#endif
Expand Down Expand Up @@ -863,9 +863,9 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
SceIoStat stat_buf;
int dir_ret;
char *tmp = strdup(path);
size_t len = strlen(tmp);
if (tmp[len-1] == '/')
tmp[len-1] = '\0';
size_t _len = strlen(tmp);
if (tmp[_len-1] == '/')
tmp[_len-1] = '\0';

dir_ret = sceIoGetstat(tmp, &stat_buf);
free(tmp);
Expand Down Expand Up @@ -922,16 +922,16 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
/* On GEKKO platforms, paths cannot have
* trailing slashes - we must therefore
* remove them */
size_t len;
size_t _len;
char *path_buf = NULL;
struct stat stat_buf;

if (!(path_buf = strdup(path)))
return 0;

if ((len = strlen(path_buf)) > 0)
if (path_buf[len - 1] == '/')
path_buf[len - 1] = '\0';
if ((_len = strlen(path_buf)) > 0)
if (path_buf[_len - 1] == '/')
path_buf[_len - 1] = '\0';

if (stat(path_buf, &stat_buf) < 0)
{
Expand All @@ -940,7 +940,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
}

free(path_buf);

if (size)
*size = (int32_t)stat_buf.st_size;

Expand Down Expand Up @@ -1007,11 +1007,11 @@ int retro_vfs_mkdir_impl(const char *dir)

if (dir_buf)
{
size_t len = strlen(dir_buf);
size_t _len = strlen(dir_buf);

if (len > 0)
if (dir_buf[len - 1] == '/')
dir_buf[len - 1] = '\0';
if (_len > 0)
if (dir_buf[_len - 1] == '/')
dir_buf[_len - 1] = '\0';

ret = mkdir(dir_buf, 0750);

Expand Down
8 changes: 4 additions & 4 deletions manual_content_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ bool manual_content_scan_get_task_config(
manual_content_scan_task_config_t *task_config,
const char *path_dir_playlist)
{
size_t len;
size_t _len;
if (!task_config)
return false;

Expand Down Expand Up @@ -983,13 +983,13 @@ bool manual_content_scan_get_task_config(

/* Now we have a valid system name, can generate
* a 'database' name... */
len = strlcpy(
_len = strlcpy(
task_config->database_name,
task_config->system_name,
sizeof(task_config->database_name));
strlcpy(task_config->database_name + len,
strlcpy(task_config->database_name + _len,
".lpl",
sizeof(task_config->database_name) - len);
sizeof(task_config->database_name) - _len);

/* ...which can in turn be used to generate the
* playlist path */
Expand Down
12 changes: 6 additions & 6 deletions menu/menu_contentless_cores.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,14 @@ static void contentless_cores_load_icons(contentless_cores_state_t *state)
struct texture_image ti;
const char *icon_name =
core_info->databases_list->elems[0].data;
size_t len = fill_pathname_join_special(
size_t _len = fill_pathname_join_special(
icon_path, icon_directory,
icon_name, sizeof(icon_path));
icon_path[ len] = '.';
icon_path[++len] = 'p';
icon_path[++len] = 'n';
icon_path[++len] = 'g';
icon_path[++len] = '\0';
icon_path[ _len] = '.';
icon_path[++_len] = 'p';
icon_path[++_len] = 'n';
icon_path[++_len] = 'g';
icon_path[++_len] = '\0';

ti.pixels = NULL;
ti.width = 0;
Expand Down
Loading

0 comments on commit ed58e4a

Please sign in to comment.