Simplify do/while loops

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
This commit is contained in:
Dimitri Papadopoulos
2025-08-27 10:48:14 +03:00
parent 284f2ecde5
commit 2a2334513c
2 changed files with 18 additions and 28 deletions

View File

@@ -614,9 +614,8 @@ static void load_iroutes(struct cfg_st *config)
dir = opendir(config->per_user_dir);
if (dir != NULL) {
do {
r = readdir(dir);
if (r != NULL && r->d_type == DT_REG) {
for (r = readdir(dir); r != NULL; r = readdir(dir)) {
if (r->d_type == DT_REG) {
ret = snprintf(path, sizeof(path), "%s/%s",
config->per_user_dir, r->d_name);
if (ret != (int)strlen(path)) {
@@ -627,7 +626,7 @@ static void load_iroutes(struct cfg_st *config)
}
append_iroutes_from_file(config, path);
}
} while (r != NULL);
}
closedir(dir);
}
}

View File

@@ -742,19 +742,14 @@ url_handler_fn http_get_url_handler(const char *url)
const struct known_urls_st *p;
unsigned int len = strlen(url);
p = known_urls;
do {
if (p->url != NULL) {
if ((len == p->url_size && strcmp(p->url, url) == 0) ||
(len >= p->url_size &&
strncmp(p->url, url, p->url_size) == 0 &&
(p->partial_match != 0 ||
url[p->url_size] == '/' ||
url[p->url_size] == '?')))
return p->get_handler;
}
p++;
} while (p->url != NULL);
for (p = known_urls; p->url != NULL; p++) {
if ((len == p->url_size && strcmp(p->url, url) == 0) ||
(len >= p->url_size &&
strncmp(p->url, url, p->url_size) == 0 &&
(p->partial_match != 0 || url[p->url_size] == '/' ||
url[p->url_size] == '?')))
return p->get_handler;
}
return NULL;
}
@@ -766,17 +761,13 @@ url_handler_fn http_post_known_service_check(struct worker_st *ws,
unsigned int len = strlen(url);
unsigned int i;
p = known_urls;
do {
if (p->url != NULL) {
if ((len == p->url_size && strcmp(p->url, url) == 0) ||
(len > p->url_size &&
strncmp(p->url, url, p->url_size) == 0 &&
p->partial_match == 0 && url[p->url_size] == '?'))
return p->post_handler;
}
p++;
} while (p->url != NULL);
for (p = known_urls; p->url != NULL; p++) {
if ((len == p->url_size && strcmp(p->url, url) == 0) ||
(len > p->url_size &&
strncmp(p->url, url, p->url_size) == 0 &&
p->partial_match == 0 && url[p->url_size] == '?'))
return p->post_handler;
}
for (i = 0; i < WSCONFIG(ws)->kkdcp_size; i++) {
if (WSCONFIG(ws)->kkdcp[i].url &&