MCPcopy Create free account
hub / github.com/F-Stack/f-stack / res_find

Function res_find

freebsd/kern/subr_hints.c:124–299  ·  view source on GitHub ↗

* Evil wildcarding resource string lookup. * This walks the supplied env string table and returns a match. * The start point can be remembered for incremental searches. */

Source from the content-addressed store, hash-verified

122 * The start point can be remembered for incremental searches.
123 */
124static int
125res_find(char **hintp_cookie, int *line, int *startln,
126 const char *name, int *unit, const char *resname, const char *value,
127 const char **ret_name, int *ret_namelen, int *ret_unit,
128 const char **ret_resname, int *ret_resnamelen, const char **ret_value)
129{
130 int fbacklvl = FBACK_MDENV, i = 0, n = 0;
131 char r_name[32];
132 int r_unit;
133 char r_resname[32];
134 char r_value[128];
135 const char *s, *cp;
136 char *hintp, *p;
137 bool dyn_used = false;
138
139 /*
140 * We are expecting that the caller will pass us a hintp_cookie that
141 * they are tracking. Upon entry, if *hintp_cookie is *not* set, this
142 * indicates to us that we should be figuring out based on the current
143 * environment where to search. This keeps us sane throughout the
144 * entirety of a single search.
145 */
146 if (*hintp_cookie == NULL) {
147 hintp = NULL;
148 if (hintenv_merged) {
149 /*
150 * static_hints, if it was previously used, has
151 * already been folded in to the environment
152 * by this point.
153 */
154 mtx_lock(&kenv_lock);
155 cp = kenvp[0];
156 for (i = 0; cp != NULL; cp = kenvp[++i]) {
157 if (!strncmp(cp, "hint.", 5)) {
158 hintp = kenvp[0];
159 break;
160 }
161 }
162 mtx_unlock(&kenv_lock);
163 dyn_used = true;
164 } else {
165 /*
166 * We'll have a chance to keep coming back here until
167 * we've actually exhausted all of our possibilities.
168 * We might have chosen the MD/Static env because it
169 * had some kind of hints, but perhaps it didn't have
170 * the hint we are looking for. We don't provide any
171 * fallback when searching the dynamic environment.
172 */
173fallback:
174 if (dyn_used || fbacklvl >= FBACK_STATIC)
175 return (ENOENT);
176
177 switch (fbacklvl) {
178 case FBACK_MDENV:
179 fbacklvl++;
180 if (_res_checkenv(md_envp)) {
181 hintp = md_envp;

Callers 1

resource_findFunction · 0.85

Calls 8

strncmpFunction · 0.85
_res_checkenvFunction · 0.85
sscanfFunction · 0.85
strchrFunction · 0.85
strcmpFunction · 0.85
mtx_lockFunction · 0.70
mtx_unlockFunction · 0.70
printfFunction · 0.70

Tested by

no test coverage detected