* 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. */
| 520 | * backslashes, with \\ representing a literal backslash. |
| 521 | */ |
| 522 | void |
| 523 | pg_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. |
no test coverage detected