mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
dln_find_1: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
This commit is contained in:
parent
99073f49bf
commit
5e96054519
Notes:
git
2020-06-29 11:07:08 +09:00
1 changed files with 20 additions and 14 deletions
34
dln_find.c
34
dln_find.c
|
@ -248,26 +248,14 @@ dln_find_1(const char *fname, const char *path, char *fbuf, size_t size,
|
||||||
/* now append the file name */
|
/* now append the file name */
|
||||||
i = fnlen;
|
i = fnlen;
|
||||||
if (fspace < i) {
|
if (fspace < i) {
|
||||||
toolong:
|
goto toolong;
|
||||||
PATHNAME_TOO_LONG();
|
|
||||||
goto next;
|
|
||||||
}
|
}
|
||||||
fspace -= i;
|
fspace -= i;
|
||||||
memcpy(bp, fname, i + 1);
|
memcpy(bp, fname, i + 1);
|
||||||
|
|
||||||
#if defined(DOSISH)
|
#if defined(DOSISH)
|
||||||
if (exe_flag && !ext) {
|
if (exe_flag && !ext) {
|
||||||
needs_extension:
|
goto needs_extension;
|
||||||
for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) {
|
|
||||||
if (fspace < strlen(extension[j])) {
|
|
||||||
PATHNAME_TOO_LONG();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
strlcpy(bp + i, extension[j], fspace);
|
|
||||||
if (stat(fbuf, &st) == 0)
|
|
||||||
return fbuf;
|
|
||||||
}
|
|
||||||
goto next;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -284,7 +272,25 @@ dln_find_1(const char *fname, const char *path, char *fbuf, size_t size,
|
||||||
if (*ep == '\0') {
|
if (*ep == '\0') {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
|
|
||||||
|
toolong:
|
||||||
|
PATHNAME_TOO_LONG();
|
||||||
|
goto next;
|
||||||
|
|
||||||
|
#if defined(DOSISH)
|
||||||
|
needs_extension:
|
||||||
|
for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) {
|
||||||
|
if (fspace < strlen(extension[j])) {
|
||||||
|
PATHNAME_TOO_LONG();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
strlcpy(bp + i, extension[j], fspace);
|
||||||
|
if (stat(fbuf, &st) == 0)
|
||||||
|
return fbuf;
|
||||||
|
}
|
||||||
|
goto next;
|
||||||
|
#endif
|
||||||
/* otherwise try the next component in the search path */
|
/* otherwise try the next component in the search path */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue