diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-12-04 19:36:06 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-12-04 19:36:06 -0300 |
commit | 0b9466fce2cf4f8c32b3a9170ca272829aa11e66 (patch) | |
tree | 386bbebd3e2de5a4b4443f6fdfc5c130c30f3b1b /src/bin/psql/prompt.c | |
parent | b1abfec825472434ea445b9700eaa80cde9da86a (diff) |
Offer pnstrdup to frontend code
We already had it on the backend. Frontend can also use it now.
Discussion: https://postgr.es/m/20191204144021.GA17976@alvherre.pgsql
Diffstat (limited to 'src/bin/psql/prompt.c')
-rw-r--r-- | src/bin/psql/prompt.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c index 41c6f21ecfc..11991815213 100644 --- a/src/bin/psql/prompt.c +++ b/src/bin/psql/prompt.c @@ -270,13 +270,10 @@ get_prompt(promptStatus_t status, ConditionalStack cstack) /* execute command */ case '`': { - FILE *fd; - char *file = pg_strdup(p + 1); - int cmdend; + int cmdend = strcspn(p + 1, "`"); + char *file = pnstrdup(p + 1, cmdend); + FILE *fd = popen(file, "r"); - cmdend = strcspn(file, "`"); - file[cmdend] = '\0'; - fd = popen(file, "r"); if (fd) { if (fgets(buf, sizeof(buf), fd) == NULL) @@ -295,13 +292,10 @@ get_prompt(promptStatus_t status, ConditionalStack cstack) /* interpolate variable */ case ':': { - char *name; + int nameend = strcspn(p + 1, ":"); + char *name = pnstrdup(p + 1, nameend); const char *val; - int nameend; - name = pg_strdup(p + 1); - nameend = strcspn(name, ":"); - name[nameend] = '\0'; val = GetVariable(pset.vars, name); if (val) strlcpy(buf, val, sizeof(buf)); |