From 27c033ed98d0ed8ee05caf440ae648f42fa5f9d6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 28 Oct 2007 21:55:52 +0000 Subject: Make pg_dump and friends consistently report both the filename and the errno string when complaining of fopen failures. Per gripe from Bob Pawley, it's not always instantly obvious to the user which name we tried to open. --- src/bin/pg_dump/pg_backup_custom.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/bin/pg_dump/pg_backup_custom.c') diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c index 923acce55a9..5791ec78128 100644 --- a/src/bin/pg_dump/pg_backup_custom.c +++ b/src/bin/pg_dump/pg_backup_custom.c @@ -19,7 +19,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.39 2007/08/06 01:38:14 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.40 2007/10/28 21:55:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -169,23 +169,38 @@ InitArchiveFmt_Custom(ArchiveHandle *AH) if (AH->mode == archModeWrite) { if (AH->fSpec && strcmp(AH->fSpec, "") != 0) + { AH->FH = fopen(AH->fSpec, PG_BINARY_W); + if (!AH->FH) + die_horribly(AH, modulename, "could not open output file \"%s\": %s\n", + AH->fSpec, strerror(errno)); + } else + { AH->FH = stdout; - - if (!AH->FH) - die_horribly(AH, modulename, "could not open output file \"%s\": %s\n", AH->fSpec, strerror(errno)); + if (!AH->FH) + die_horribly(AH, modulename, "could not open output file: %s\n", + strerror(errno)); + } ctx->hasSeek = checkSeek(AH->FH); } else { if (AH->fSpec && strcmp(AH->fSpec, "") != 0) + { AH->FH = fopen(AH->fSpec, PG_BINARY_R); + if (!AH->FH) + die_horribly(AH, modulename, "could not open input file \"%s\": %s\n", + AH->fSpec, strerror(errno)); + } else + { AH->FH = stdin; - if (!AH->FH) - die_horribly(AH, modulename, "could not open input file \"%s\": %s\n", AH->fSpec, strerror(errno)); + if (!AH->FH) + die_horribly(AH, modulename, "could not open input file: %s\n", + strerror(errno)); + } ctx->hasSeek = checkSeek(AH->FH); -- cgit v1.2.3