Skip to content

Commit

Permalink
Standardize local len variable naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jan 15, 2025
1 parent 47d1992 commit 047e04e
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 163 deletions.
6 changes: 3 additions & 3 deletions bluetooth/drivers/bluetoothctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ static void bluetoothctl_scan(void *data)

while (fgets(line, 512, dev_file))
{
size_t len = strlen(line);
if (len > 0 && line[len-1] == '\n')
line[--len] = '\0';
size_t _len = strlen(line);
if (_len > 0 && line[_len - 1] == '\n')
line[--_len] = '\0';

string_list_append(btctl->lines, line, attr);
}
Expand Down
14 changes: 6 additions & 8 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -4088,7 +4088,6 @@ static bool input_keyboard_line_event(
bool ret = false;
const char *word = NULL;
char c = (character >= 128) ? '?' : character;

#ifdef HAVE_LANGEXTRA
static uint32_t composition = 0;
/* reset composition, when edit box is opened. */
Expand All @@ -4099,12 +4098,12 @@ static bool input_keyboard_line_event(
composition = 0;
if (IS_COMPOSITION(character) || IS_END_COMPOSITION(character))
{
size_t len = strlen((char*)&composition);
if (composition && state->buffer && state->size >= len && state->ptr >= len)
size_t _len = strlen((char*)&composition);
if (composition && state->buffer && state->size >= _len && state->ptr >= _len)
{
memmove(state->buffer + state->ptr-len, state->buffer + state->ptr, len + 1);
state->ptr -= len;
state->size -= len;
memmove(state->buffer + state->ptr - _len, state->buffer + state->ptr, _len + 1);
state->ptr -= _len;
state->size -= _len;
}
if (IS_COMPOSITION_KR(character) && composition)
{
Expand All @@ -4123,7 +4122,7 @@ static bool input_keyboard_line_event(
composition = character & 0xffffff;
character &= 0xffffff;
}
if (len && composition == 0)
if (_len && composition == 0)
word = state->buffer;
if (character)
input_keyboard_line_append(state, (char*)&character, strlen((char*)&character));
Expand All @@ -4134,7 +4133,6 @@ static bool input_keyboard_line_event(

/* Treat extended chars as ? as we cannot support
* printable characters for unicode stuff. */

if (c == '\r' || c == '\n')
{
state->cb(state->userdata, state->buffer);
Expand Down
23 changes: 11 additions & 12 deletions libretro-common/cdrom/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,12 +1000,11 @@ int cdrom_set_read_speed(libretro_vfs_implementation_file *stream, unsigned spee

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)
{
int i;
unsigned char buf[2352] = {0};
unsigned short data_len = 0;
size_t len = 0;
size_t pos = 0;
size_t _len = 0, pos = 0;
int rv = 0;
int i;

if (!out_buf || !out_len || !num_tracks || !toc)
{
Expand Down Expand Up @@ -1052,10 +1051,10 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
return 1;
}

len = CDROM_CUE_TRACK_BYTES * (*num_tracks);
_len = CDROM_CUE_TRACK_BYTES * (*num_tracks);
toc->num_tracks = *num_tracks;
*out_buf = (char*)calloc(1, len);
*out_len = len;
*out_buf = (char*)calloc(1, _len);
*out_len = _len;

for (i = 0; i < (data_len - 2) / 11; i++)
{
Expand Down Expand Up @@ -1104,11 +1103,11 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
track_type = "MODE2/2352";

#if defined(_WIN32) && !defined(_XBOX)
pos += snprintf(*out_buf + pos, len - pos, "FILE \"cdrom://%c:/drive-track%02d.bin\" BINARY\n", cdrom_drive, point);
pos += snprintf(*out_buf + pos, _len - pos, "FILE \"cdrom://%c:/drive-track%02d.bin\" BINARY\n", cdrom_drive, point);
#else
pos += snprintf(*out_buf + pos, len - pos, "FILE \"cdrom://drive%c-track%02d.bin\" BINARY\n", cdrom_drive, point);
pos += snprintf(*out_buf + pos, _len - pos, "FILE \"cdrom://drive%c-track%02d.bin\" BINARY\n", cdrom_drive, point);
#endif
pos += snprintf(*out_buf + pos, len - pos, " TRACK %02d %s\n", point, track_type);
pos += snprintf(*out_buf + pos, _len - pos, " TRACK %02d %s\n", point, track_type);

{
unsigned pregap_lba_len = toc->track[point - 1].lba - toc->track[point - 1].lba_start;
Expand All @@ -1121,11 +1120,11 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si

cdrom_lba_to_msf(pregap_lba_len, &min, &sec, &frame);

pos += snprintf(*out_buf + pos, len - pos, " INDEX 00 00:00:00\n");
pos += snprintf(*out_buf + pos, len - pos, " INDEX 01 %02u:%02u:%02u\n", (unsigned)min, (unsigned)sec, (unsigned)frame);
pos += snprintf(*out_buf + pos, _len - pos, " INDEX 00 00:00:00\n");
pos += snprintf(*out_buf + pos, _len - pos, " INDEX 01 %02u:%02u:%02u\n", (unsigned)min, (unsigned)sec, (unsigned)frame);
}
else
pos += snprintf(*out_buf + pos, len - pos, " INDEX 01 00:00:00\n");
pos += snprintf(*out_buf + pos, _len - pos, " INDEX 01 00:00:00\n");
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions libretro-common/compat/compat_posix_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ int retro_strcasecmp__(const char *a, const char *b)

char *retro_strdup__(const char *orig)
{
size_t len = strlen(orig) + 1;
char *ret = (char*)malloc(len);
size_t _len = strlen(orig) + 1;
char *ret = (char*)malloc(_len);
if (!ret)
return NULL;

strlcpy(ret, orig, len);
strlcpy(ret, orig, _len);
return ret;
}

Expand Down
39 changes: 16 additions & 23 deletions libretro-common/compat/compat_strl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,28 @@
/* Implementation of strlcpy()/strlcat() based on OpenBSD. */

#ifndef __MACH__

size_t strlcpy(char *dest, const char *source, size_t size)
size_t strlcpy(char *s, const char *source, size_t len)
{
size_t src_size = 0;
size_t n = size;

if (n)
while (--n && (*dest++ = *source++)) src_size++;

if (!n)
size_t _len = len;
size_t __len = 0;
if (_len)
while (--_len && (*s++ = *source++)) __len++;
if (!_len)
{
if (size) *dest = '\0';
while (*source++) src_size++;
if (len) *s = '\0';
while (*source++) __len++;
}

return src_size;
return __len;
}

size_t strlcat(char *dest, const char *source, size_t size)
size_t strlcat(char *s, const char *source, size_t len)
{
size_t len = strlen(dest);

dest += len;

if (len > size)
size = 0;
size_t _len = strlen(s);
s += _len;
if (_len > len)
len = 0;
else
size -= len;

return len + strlcpy(dest, source, size);
len -= _len;
return _len + strlcpy(s, source, len);
}
#endif
6 changes: 3 additions & 3 deletions libretro-common/file/file_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,11 +1414,11 @@ size_t fill_pathname_application_path(char *s, size_t len)
}
#elif defined(__QNX__)
char *buff = malloc(len);
size_t rv = 0;
size_t _len = 0;
if (_cmdname(buff))
rv = strlcpy(s, buff, len);
_len = strlcpy(s, buff, len);
free(buff);
return rv;
return _len;
#else
size_t i;
static const char *exts[] = { "exe", "file", "path/a.out" };
Expand Down
8 changes: 4 additions & 4 deletions libretro-common/formats/m3u/m3u_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,16 @@ static bool m3u_file_load(m3u_file_t *m3u_file)

if (token_ptr)
{
size_t len = (size_t)(1 + token_ptr - line);
size_t _len = (size_t)(1 + token_ptr - line);

/* Get entry_path segment */
if (len > 0)
if (_len > 0)
{
memset(entry_path, 0, sizeof(entry_path));
strlcpy(
entry_path, line,
((len < PATH_MAX_LENGTH ?
len : PATH_MAX_LENGTH) * sizeof(char)));
((_len < PATH_MAX_LENGTH ?
_len : PATH_MAX_LENGTH) * sizeof(char)));
string_trim_whitespace_right(entry_path);
string_trim_whitespace_left(entry_path);
}
Expand Down
31 changes: 14 additions & 17 deletions libretro-common/media/media_detect_cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,31 @@

/*#define MEDIA_CUE_PARSE_DEBUG*/

static void media_zero_trailing_spaces(char *buf, size_t len)
static void media_zero_trailing_spaces(char *s, size_t len)
{
int i;

for (i = len - 1; i >= 0; i--)
{
if (buf[i] == ' ')
buf[i] = '\0';
else if (buf[i] != '\0')
if (s[i] == ' ')
s[i] = '\0';
else if (s[i] != '\0')
break;
}
}

static bool media_skip_spaces(const char **buf, size_t len)
static bool media_skip_spaces(const char **s, size_t len)
{
if (buf && *buf && **buf)
if (s && *s && **s)
{
size_t i;
for (i = 0; i < len; i++)
{
if ((*buf)[i] == ' ' || (*buf)[i] == '\t')
if ((*s)[i] == ' ' || (*s)[i] == '\t')
continue;

*buf += i;
*s += i;
return true;
}
}

return false;
}

Expand Down Expand Up @@ -86,7 +83,7 @@ bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)

while (!filestream_eof(file) && (line = filestream_getline(file)))
{
size_t len = 0;
size_t _len = 0;
const char *command = NULL;

if (string_is_empty(line))
Expand All @@ -95,15 +92,15 @@ bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)
continue;
}

len = strlen(line);
_len = strlen(line);
command = line;

media_skip_spaces(&command, len);
media_skip_spaces(&command, _len);

if (!found_file && !strncasecmp(command, "FILE", 4))
{
const char *file = command + 4;
media_skip_spaces(&file, len - 4);
media_skip_spaces(&file, _len - 4);

if (!string_is_empty(file))
{
Expand Down Expand Up @@ -137,7 +134,7 @@ bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)
else if (found_file && !found_track && !strncasecmp(command, "TRACK", 5))
{
const char *track = command + 5;
media_skip_spaces(&track, len - 5);
media_skip_spaces(&track, _len - 5);

if (!string_is_empty(track))
{
Expand Down Expand Up @@ -173,7 +170,7 @@ bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)
else if (found_file && found_track && first_data_track && !strncasecmp(command, "INDEX", 5))
{
const char *index = command + 5;
media_skip_spaces(&index, len - 5);
media_skip_spaces(&index, _len - 5);

if (!string_is_empty(index))
{
Expand Down
14 changes: 5 additions & 9 deletions libretro-common/memmap/memmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ void* mmap(void *addr, size_t len, int prot, int flags,

int munmap(void *addr, size_t len)
{
if (!UnmapViewOfFile(addr))
return -1;
return 0;
return (UnmapViewOfFile(addr)) ? 0 : -1;
}

int mprotect(void *addr, size_t len, int prot)
Expand Down Expand Up @@ -137,23 +135,21 @@ int mprotect(void *addr, size_t len, int prot)

int memsync(void *start, void *end)
{
size_t len = (char*)end - (char*)start;
size_t _len = (char*)end - (char*)start;
#if defined(__MACH__) && defined(__arm__)
sys_dcache_flush(start ,len);
sys_icache_invalidate(start, len);
sys_dcache_flush(start, _len);
sys_icache_invalidate(start, _len);
return 0;
#elif defined(__arm__) && !defined(__QNX__)
(void)len;
__clear_cache(start, end);
return 0;
#elif defined(HAVE_MMAN)
return msync(start, len, MS_SYNC | MS_INVALIDATE
return msync(start, _len, MS_SYNC | MS_INVALIDATE
#ifdef __QNX__
MS_CACHE_ONLY
#endif
);
#else
(void)len;
return 0;
#endif
}
Expand Down
16 changes: 6 additions & 10 deletions libretro-common/vfs/vfs_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ libretro_vfs_implementation_dir *retro_vfs_opendir_impl(
{
#if defined(_WIN32)
char path_buf[1024];
size_t copied = 0;
size_t _len;
#if defined(LEGACY_WIN32)
char *path_local = NULL;
#else
Expand All @@ -1095,25 +1095,21 @@ libretro_vfs_implementation_dir *retro_vfs_opendir_impl(
rdir->orig_path = strdup(name);

#if defined(_WIN32)
copied = strlcpy(path_buf, name, sizeof(path_buf));

_len = strlcpy(path_buf, name, sizeof(path_buf));
/* Non-NT platforms don't like extra slashes in the path */
if (path_buf[copied - 1] != '\\')
path_buf [copied++] = '\\';

path_buf[copied ] = '*';
path_buf[copied+1] = '\0';
if (path_buf[_len - 1] != '\\')
path_buf [_len++] = '\\';

path_buf[_len ] = '*';
path_buf[_len + 1] = '\0';
#if defined(LEGACY_WIN32)
path_local = utf8_to_local_string_alloc(path_buf);
rdir->directory = FindFirstFile(path_local, &rdir->entry);

if (path_local)
free(path_local);
#else
path_wide = utf8_to_utf16_string_alloc(path_buf);
rdir->directory = FindFirstFileW(path_wide, &rdir->entry);

if (path_wide)
free(path_wide);
#endif
Expand Down
Loading

0 comments on commit 047e04e

Please sign in to comment.