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. */
| 230 | The returned pointer should not be freed. |
| 231 | Return NULL if not a valid ${VARNAME} syntax. */ |
| 232 | static char * |
| 233 | extract_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. */ |
| 256 | struct splitbuf |
no test coverage detected