summaryrefslogtreecommitdiff
path: root/src/bin/psql/copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql/copy.c')
-rw-r--r--src/bin/psql/copy.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index dbb2255db6c..9e815b136ed 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -345,13 +345,20 @@ do_copy(const char *args)
if (!options->program)
{
+ int result;
+
/* make sure the specified file is not a directory */
- fstat(fileno(copystream), &st);
- if (S_ISDIR(st.st_mode))
- {
- fclose(copystream);
+ if ((result = fstat(fileno(copystream), &st)) < 0)
+ psql_error("could not stat file: %s\n",
+ strerror(errno));
+
+ if (result == 0 && S_ISDIR(st.st_mode))
psql_error("%s: cannot copy from/to a directory\n",
options->file);
+
+ if (result < 0 || S_ISDIR(st.st_mode))
+ {
+ fclose(copystream);
free_copy_options(options);
return false;
}