MCPcopy Create free account
hub / github.com/apache/cloudberry / pg_split_opts

Function pg_split_opts

src/backend/utils/init/postinit.c:522–567  ·  view source on GitHub ↗

* pg_split_opts -- split a string of options and append it to an argv array * * The caller is responsible for ensuring the argv array is large enough. The * maximum possible number of arguments added by this routine is * (strlen(optstr) + 1) / 2. * * Because some option values can contain spaces we allow escaping using * backslashes, with \\ representing a literal backslash. */

Source from the content-addressed store, hash-verified

520 * backslashes, with \\ representing a literal backslash.
521 */
522void
523pg_split_opts(char **argv, int *argcp, const char *optstr)
524{
525 StringInfoData s;
526
527 initStringInfo(&s);
528
529 while (*optstr)
530 {
531 bool last_was_escape = false;
532
533 resetStringInfo(&s);
534
535 /* skip over leading space */
536 while (isspace((unsigned char) *optstr))
537 optstr++;
538
539 if (*optstr == '\0')
540 break;
541
542 /*
543 * Parse a single option, stopping at the first space, unless it's
544 * escaped.
545 */
546 while (*optstr)
547 {
548 if (isspace((unsigned char) *optstr) && !last_was_escape)
549 break;
550
551 if (!last_was_escape && *optstr == '\\')
552 last_was_escape = true;
553 else
554 {
555 last_was_escape = false;
556 appendStringInfoChar(&s, *optstr);
557 }
558
559 optstr++;
560 }
561
562 /* now store the option in the next argv[] position */
563 argv[(*argcp)++] = pstrdup(s.data);
564 }
565
566 pfree(s.data);
567}
568
569/*
570 * Initialize MaxBackends value from config options.

Callers 2

process_startup_optionsFunction · 0.85

Calls 5

initStringInfoFunction · 0.85
resetStringInfoFunction · 0.85
appendStringInfoCharFunction · 0.85
pstrdupFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected