MCPcopy Create free account
hub / github.com/coreutils/coreutils / extract_varname

Function extract_varname

src/env.c:232–253  ·  view source on GitHub ↗

Return a pointer to a static buffer containing the VARNAME as extracted from a '${VARNAME}' string. The returned string will be NUL terminated. The returned pointer should not be freed. Return NULL if not a valid ${VARNAME} syntax. */

Source from the content-addressed store, hash-verified

230 The returned pointer should not be freed.
231 Return NULL if not a valid ${VARNAME} syntax. */
232static char *
233extract_varname (char const *str)
234{
235 char const *p = scan_varname (str);
236
237 if (!p)
238 return NULL;
239
240 /* -2 and +2 (below) account for the '${' prefix. */
241 idx_t i = p - str - 2;
242
243 if (i >= vnlen)
244 {
245 free (varname);
246 varname = xpalloc (NULL, &vnlen, i + 1 - vnlen, -1, sizeof *varname);
247 }
248
249 memcpy (varname, str + 2, i);
250 varname[i] = 0;
251
252 return varname;
253}
254
255/* Temporary buffer used by --split-string processing. */
256struct splitbuf

Callers 1

build_argvFunction · 0.85

Calls 1

scan_varnameFunction · 0.85

Tested by

no test coverage detected