Skip to content

Commit 03325ca

Browse files
committed
to_squash: Add offset determining
1 parent f89a074 commit 03325ca

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ctl/ctl.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ int umfCtlExec(const char *name, void *ctx, void *arg) {
9999
* ctl_find_node -- (internal) searches for a matching entry point in the
100100
* provided nodes
101101
*
102+
* Name offset is used to return the offset of the name in the query string.
102103
* The caller is responsible for freeing all of the allocated indexes,
103104
* regardless of the return value.
104105
*/
105106
static const struct ctl_node *ctl_find_node(const struct ctl_node *nodes,
106107
const char *name,
107-
struct ctl_index_utlist *indexes) {
108+
struct ctl_index_utlist *indexes, int *name_offset) {
108109
const struct ctl_node *n = NULL;
109110
char *sptr = NULL;
110111
char *parse_str = Strdup(name);
@@ -119,6 +120,7 @@ static const struct ctl_node *ctl_find_node(const struct ctl_node *nodes,
119120
* in the main ctl tree.
120121
*/
121122
while (node_name != NULL) {
123+
*name_offset = node_name - parse_str;
122124
if (n != NULL && n->type == CTL_NODE_SUBTREE) {
123125
break;
124126
}
@@ -362,13 +364,14 @@ int ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source,
362364
}
363365

364366
int ret = -1;
367+
int name_offset = 0;
365368

366-
const struct ctl_node *n = ctl_find_node(CTL_NODE(global), name, indexes);
369+
const struct ctl_node *n = ctl_find_node(CTL_NODE(global), name, indexes, &name_offset);
367370

368371
if (n == NULL && ctl) {
369372
ctl_delete_indexes(indexes);
370373
indexes = NULL;
371-
n = ctl_find_node(ctl->root, name, indexes);
374+
n = ctl_find_node(ctl->root, name, indexes, &name_offset);
372375
}
373376

374377
if (n == NULL ||

0 commit comments

Comments
 (0)