Allow fseeko in pg_dump only if fseeko() will work for all supported file
authorBruce Momjian
Fri, 25 Oct 2002 01:33:17 +0000 (01:33 +0000)
committerBruce Momjian
Fri, 25 Oct 2002 01:33:17 +0000 (01:33 +0000)
sizes.

src/bin/pg_dump/common.c
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_backup_custom.c
src/bin/pg_dump/pg_backup_files.c
src/bin/pg_dump/pg_backup_tar.c

index 7870a0d66d21d6a8d2e2c526b9e3bd15494195f3..a703660aa243d638030bec6905fd74967fe34d22 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.71 2002/10/09 16:20:25 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.72 2002/10/25 01:33:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -290,7 +290,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
         * attr with the same name, then only dump it if:
         *
         * - it is NOT NULL and zero parents are NOT NULL
-        *   OR 
+        *   OR
         * - it has a default value AND the default value does not match
         *   all parent default values, or no parents specify a default.
         *
index d56ebdcd06c0e0793f5acbb66f3fed0d1cc596c7..c5cfa2f405ed88fc287685d670a1bfb94772259d 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.59 2002/10/22 19:15:23 momjian Exp $
+ *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.60 2002/10/25 01:33:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2338,6 +2338,32 @@ ReadHead(ArchiveHandle *AH)
 }
 
 
+/*
+ * checkSeek
+ *   check to see if fseek can be performed.
+ */
+
+bool
+checkSeek(FILE *fp)
+{
+
+   if (fseek(fp, 0, SEEK_CUR) != 0)
+       return false;
+   else if (sizeof(off_t) > sizeof(long))
+   /*
+    *  At this point, off_t is too large for long, so we return
+    *  based on whether an off_t version of fseek is available.
+    */
+#ifdef HAVE_FSEEKO
+       return true;
+#else
+       return false;
+#endif
+   else
+       return true;
+}
+
+
 static void
 _SortToc(ArchiveHandle *AH, TocSortCompareFn fn)
 {
index 980d262e93d8d20139ce2dd22911c38241dd614f..73b5c29c3298f4b9e4e37c0a167552df0a949b54 100644 (file)
@@ -17,7 +17,7 @@
  *
  *
  * IDENTIFICATION
- *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.48 2002/10/22 19:15:23 momjian Exp $
+ *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.49 2002/10/25 01:33:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -27,6 +27,7 @@
 
 #include "postgres_fe.h"
 
+#include 
 #include 
 #include 
 
@@ -284,6 +285,7 @@ extern void ReadToc(ArchiveHandle *AH);
 extern void WriteDataChunks(ArchiveHandle *AH);
 
 extern int TocIDRequired(ArchiveHandle *AH, int id, RestoreOptions *ropt);
+extern bool checkSeek(FILE *fp);
 
 /*
  * Mandatory routines for each supported format
index 873bfb59ce829c11e6a70549edc50d2027008144..c2fcef7536e7f7d08eff8115ac51a3b86a268a44 100644 (file)
@@ -19,7 +19,7 @@
  *
  *
  * IDENTIFICATION
- *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.22 2002/10/22 19:15:23 momjian Exp $
+ *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.23 2002/10/25 01:33:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -179,7 +179,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
        if (!AH->FH)
            die_horribly(AH, modulename, "could not open archive file %s: %s\n", AH->fSpec, strerror(errno));
 
-       ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
+       ctx->hasSeek = checkSeek(AH->FH);
    }
    else
    {
@@ -190,7 +190,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
        if (!AH->FH)
            die_horribly(AH, modulename, "could not open archive file %s: %s\n", AH->fSpec, strerror(errno));
 
-       ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
+       ctx->hasSeek = checkSeek(AH->FH);
 
        ReadHead(AH);
        ReadToc(AH);
index 1bcb16ca002b2d2fde44ebef0be61bc33e98d910..3a4914828a58e3e79b2ff2acd5eb531e3387eaa2 100644 (file)
@@ -20,7 +20,7 @@
  *
  *
  * IDENTIFICATION
- *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.20 2002/10/22 19:15:23 momjian Exp $
+ *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.21 2002/10/25 01:33:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -129,7 +129,7 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
        if (AH->FH == NULL)
            die_horribly(NULL, modulename, "could not open output file: %s\n", strerror(errno));
 
-       ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
+       ctx->hasSeek = checkSeek(AH->FH);
 
        if (AH->compression < 0 || AH->compression > 9)
            AH->compression = Z_DEFAULT_COMPRESSION;
@@ -147,7 +147,7 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
        if (AH->FH == NULL)
            die_horribly(NULL, modulename, "could not open input file: %s\n", strerror(errno));
 
-       ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
+       ctx->hasSeek = checkSeek(AH->FH);
 
        ReadHead(AH);
        ReadToc(AH);
index fdfcc95d4b15778ad03523fed230027a49e63055..6bbd1ba2a3d19c5f86808fdb0072aa9d3011d571 100644 (file)
@@ -16,7 +16,7 @@
  *
  *
  * IDENTIFICATION
- *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.31 2002/10/22 19:15:23 momjian Exp $
+ *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.32 2002/10/25 01:33:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -190,7 +190,7 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
         */
        /* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
 
-       ctx->hasSeek = (fseeko(ctx->tarFH, 0, SEEK_CUR) == 0);
+       ctx->hasSeek = checkSeek(ctx->tarFH);
 
        if (AH->compression < 0 || AH->compression > 9)
            AH->compression = Z_DEFAULT_COMPRESSION;
@@ -227,7 +227,7 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
 
        ctx->tarFHpos = 0;
 
-       ctx->hasSeek = (fseeko(ctx->tarFH, 0, SEEK_CUR) == 0);
+       ctx->hasSeek = checkSeek(ctx->tarFH);
 
        /*
         * Forcibly unmark the header as read since we use the lookahead