82 newvar =
psprintf(
"%s%s", *var, more);
93 const char *whitespace =
" \t\n\r";
136 else if (
token[0] ==
')')
192 result->
from =
false;
215 toklen = strlen(
token);
216 if (
token[0] !=
'\'' || toklen < 2 ||
token[toklen - 1] !=
'\'')
341 if ((result =
fstat(fileno(copystream), &st)) < 0)
378 int pclose_rc = pclose(copystream);
383 pg_log_error(
"could not close pipe to external command: %m");
389 reason ? reason :
"");
399 if (fclose(copystream) != 0)
449 if (OK && copystream && fwrite(
buf, 1, ret, copystream) != ret)
459 if (OK && copystream &&
fflush(copystream))
508 #define COPYBUFSIZ 8192
528 _(
"canceled by user"));
535 if (isatty(fileno(copystream)))
539 puts(
_(
"Enter data to be copied followed by a newline.\n"
540 "End with a backslash and a period on a line by itself, or an EOF signal."));
581 bool copydone =
false;
583 bool at_line_begin =
true;
596 if (at_line_begin && showprompt)
607 fgresult = fgets(&
buf[buflen],
COPYBUFSIZ - buflen, copystream);
617 linelen = strlen(fgresult);
621 if (
buf[buflen - 1] ==
'\n')
633 if ((linelen == 3 && memcmp(fgresult,
"\\.\n", 3) == 0) ||
634 (linelen == 4 && memcmp(fgresult,
"\\.\r\n", 4) == 0))
654 at_line_begin =
true;
657 at_line_begin =
false;
668 if (buflen >=
COPYBUFSIZ - 5 || (copydone && buflen > 0))
682 if (ferror(copystream))
693 _(
"aborted because of read failure")) <= 0)
706 clearerr(copystream);
727 _(
"trying to exit copy mode"));
void expand_tilde(char **filename)
volatile sig_atomic_t sigint_interrupt_enabled
sigjmp_buf sigint_interrupt_jmp
void SetShellResultVariables(int wait_result)
bool standard_strings(void)
bool SendQuery(const char *query)
static struct copy_options * parse_slash_copy(const char *args)
bool handleCopyOut(PGconn *conn, FILE *copystream, PGresult **res)
bool do_copy(const char *args)
static void xstrcat(char **var, const char *more)
bool handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
static void free_copy_options(struct copy_options *ptr)
static void PGresult * res
int PQprotocolVersion(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
void PQfreemem(void *ptr)
ExecStatusType PQresultStatus(const PGresult *res)
int PQputCopyEnd(PGconn *conn, const char *errormsg)
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
PGresult * PQgetResult(PGconn *conn)
int PQgetCopyData(PGconn *conn, char **buffer, int async)
void * pg_malloc0(size_t size)
char * pg_strdup(const char *in)
void restore_sigpipe_trap(void)
void disable_sigpipe_trap(void)
static void const char fflush(stdout)
#define pg_log_error(...)
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * get_prompt(promptStatus_t status, ConditionalStack cstack)
char * psprintf(const char *fmt,...)
char * strtokx(const char *s, const char *whitespace, const char *delim, const char *quote, char escape, bool e_strings, bool del_quotes, int encoding)
void strip_quotes(char *source, char quote, char escape, int encoding)
char * wait_result_to_str(int exitstatus)