0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-06-30 22:19:29 -04:00

check_whether_file_exists(): optimize by not using strlen() more than

needed.
This commit is contained in:
Laurent MONIN 2006-01-07 20:59:34 +01:00 committed by Laurent MONIN
parent d0be89a16c
commit 9183e0cf04

View File

@ -115,28 +115,31 @@ end_with_known_tld(unsigned char *s, int slen)
return -1;
}
/* XXX: this function writes to @name. */
static int
check_whether_file_exists(unsigned char *name)
{
/* Check POST_CHAR etc ... */
static const unsigned char chars[] = POST_CHAR_S "#?";
int i;
int namelen = strlen(name);
if (file_exists(name))
return strlen(name);
return namelen;
for (i = 0; i < sizeof(chars) - 1; i++) {
unsigned char *pos = strchr(name, chars[i]);
int namelen = -1;
unsigned char *pos = memchr(name, chars[i], namelen);
int exists;
if (!pos) continue;
*pos = 0;
if (file_exists(name))
namelen = strlen(name);
exists = file_exists(name);
*pos = chars[i];
if (namelen >= 0) return namelen;
if (exists) {
return pos - name;
}
}
return -1;