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

Function openQueryOutputFile

src/bin/psql/common.c:49–75  ·  view source on GitHub ↗

* openQueryOutputFile --- attempt to open a query output file * * fname == NULL selects stdout, else an initial '|' selects a pipe, * else plain file. * * Returns output file pointer into *fout, and is-a-pipe flag into *is_pipe. * Caller is responsible for adjusting SIGPIPE state if it's a pipe. * * On error, reports suitable error message and returns false. */

Source from the content-addressed store, hash-verified

47 * On error, reports suitable error message and returns false.
48 */
49bool
50openQueryOutputFile(const char *fname, FILE **fout, bool *is_pipe)
51{
52 if (!fname || fname[0] == '\0')
53 {
54 *fout = stdout;
55 *is_pipe = false;
56 }
57 else if (*fname == '|')
58 {
59 *fout = popen(fname + 1, "w");
60 *is_pipe = true;
61 }
62 else
63 {
64 *fout = fopen(fname, "w");
65 *is_pipe = false;
66 }
67
68 if (*fout == NULL)
69 {
70 pg_log_error("%s: %m", fname);
71 return false;
72 }
73
74 return true;
75}
76
77/*
78 * setQFout

Callers 4

setQFoutFunction · 0.85
PrintQueryTuplesFunction · 0.85
ProcessResultFunction · 0.85
ExecQueryUsingCursorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected