* Build a working copy of the constant PQconninfoOptions array. */
| 5598 | * Build a working copy of the constant PQconninfoOptions array. |
| 5599 | */ |
| 5600 | static PQconninfoOption * |
| 5601 | conninfo_init(PQExpBuffer errorMessage) |
| 5602 | { |
| 5603 | PQconninfoOption *options; |
| 5604 | PQconninfoOption *opt_dest; |
| 5605 | const internalPQconninfoOption *cur_opt; |
| 5606 | |
| 5607 | /* |
| 5608 | * Get enough memory for all options in PQconninfoOptions, even if some |
| 5609 | * end up being filtered out. |
| 5610 | */ |
| 5611 | options = (PQconninfoOption *) malloc(sizeof(PQconninfoOption) * sizeof(PQconninfoOptions) / sizeof(PQconninfoOptions[0])); |
| 5612 | if (options == NULL) |
| 5613 | { |
| 5614 | appendPQExpBufferStr(errorMessage, |
| 5615 | libpq_gettext("out of memory\n")); |
| 5616 | return NULL; |
| 5617 | } |
| 5618 | opt_dest = options; |
| 5619 | |
| 5620 | for (cur_opt = PQconninfoOptions; cur_opt->keyword; cur_opt++) |
| 5621 | { |
| 5622 | /* Only copy the public part of the struct, not the full internal */ |
| 5623 | memcpy(opt_dest, cur_opt, sizeof(PQconninfoOption)); |
| 5624 | opt_dest++; |
| 5625 | } |
| 5626 | MemSet(opt_dest, 0, sizeof(PQconninfoOption)); |
| 5627 | |
| 5628 | return options; |
| 5629 | } |
| 5630 | |
| 5631 | /* |
| 5632 | * Connection string parser |
no test coverage detected