Use off_t and size_t in pg_dump to handle file offset arithmetic correctly.
--enable-depend turn on automatic dependency tracking
--enable-cassert enable assertion checks (for debugging)
--enable-odbc build the ODBC driver package
+ --disable-largefile omit support for large files
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
done
+echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5
+echo $ECHO_N "checking for _LARGEFILE_SOURCE value needed for large files... $ECHO_C" >&6
+if test "${ac_cv_sys_largefile_source+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ while :; do
+ ac_cv_sys_largefile_source=no
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <stdio.h>
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+return !fseeko;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#define _LARGEFILE_SOURCE 1
+#include <stdio.h>
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+return !fseeko;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_sys_largefile_source=1; break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+ break
+done
+fi
+echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_source" >&5
+echo "${ECHO_T}$ac_cv_sys_largefile_source" >&6
+if test "$ac_cv_sys_largefile_source" != no; then
+
+cat >>confdefs.h <<_ACEOF
+#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source
+_ACEOF
+
+fi
+rm -f conftest*
+
+# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
+# in glibc 2.1.3, but that breaks too many other things.
+# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
+echo "$as_me:$LINENO: checking for fseeko" >&5
+echo $ECHO_N "checking for fseeko... $ECHO_C" >&6
+if test "${ac_cv_func_fseeko+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <stdio.h>
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+return fseeko && fseeko (stdin, 0, 0);
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_func_fseeko=yes
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+ac_cv_func_fseeko=no
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_fseeko" >&5
+echo "${ECHO_T}$ac_cv_func_fseeko" >&6
+if test $ac_cv_func_fseeko = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_FSEEKO 1
+_ACEOF
+
+fi
+
+
# This test makes sure that run tests work at all. Sometimes a shared
# library is found by the linker, but the runtime linker can't find it.
fi
HAVE_POSIX_SIGNALS=$pgac_cv_func_posix_signals
+if test $ac_cv_func_fseeko = yes; then
+# Check whether --enable-largefile or --disable-largefile was given.
+if test "${enable_largefile+set}" = set; then
+ enableval="$enable_largefile"
+
+fi;
+if test "$enable_largefile" != no; then
+
+ echo "$as_me:$LINENO: checking for special C compiler options needed for large files" >&5
+echo $ECHO_N "checking for special C compiler options needed for large files... $ECHO_C" >&6
+if test "${ac_cv_sys_largefile_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_cv_sys_largefile_CC=no
+ if test "$GCC" != yes; then
+ ac_save_CC=$CC
+ while :; do
+ # IRIX 6.2 and later do not support large files by default,
+ # so use the C compiler's -n32 option if that helps.
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+ We can't simply define LARGE_OFF_T to be 9223372036854775807,
+ since some C++ compilers masquerading as C compilers
+ incorrectly reject 9223372036854775807. */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+ && LARGE_OFF_T % 2147483647 == 1)
+ ? 1 : -1];
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+ rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext
+ CC="$CC -n32"
+ rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_sys_largefile_CC=' -n32'; break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext
+ break
+ done
+ CC=$ac_save_CC
+ rm -f conftest.$ac_ext
+ fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_CC" >&5
+echo "${ECHO_T}$ac_cv_sys_largefile_CC" >&6
+ if test "$ac_cv_sys_largefile_CC" != no; then
+ CC=$CC$ac_cv_sys_largefile_CC
+ fi
+
+ echo "$as_me:$LINENO: checking for _FILE_OFFSET_BITS value needed for large files" >&5
+echo $ECHO_N "checking for _FILE_OFFSET_BITS value needed for large files... $ECHO_C" >&6
+if test "${ac_cv_sys_file_offset_bits+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ while :; do
+ ac_cv_sys_file_offset_bits=no
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+ We can't simply define LARGE_OFF_T to be 9223372036854775807,
+ since some C++ compilers masquerading as C compilers
+ incorrectly reject 9223372036854775807. */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+ && LARGE_OFF_T % 2147483647 == 1)
+ ? 1 : -1];
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#define _FILE_OFFSET_BITS 64
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+ We can't simply define LARGE_OFF_T to be 9223372036854775807,
+ since some C++ compilers masquerading as C compilers
+ incorrectly reject 9223372036854775807. */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+ && LARGE_OFF_T % 2147483647 == 1)
+ ? 1 : -1];
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_sys_file_offset_bits=64; break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+ break
+done
+fi
+echo "$as_me:$LINENO: result: $ac_cv_sys_file_offset_bits" >&5
+echo "${ECHO_T}$ac_cv_sys_file_offset_bits" >&6
+if test "$ac_cv_sys_file_offset_bits" != no; then
+
+cat >>confdefs.h <<_ACEOF
+#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits
+_ACEOF
+
+fi
+rm -f conftest*
+ echo "$as_me:$LINENO: checking for _LARGE_FILES value needed for large files" >&5
+echo $ECHO_N "checking for _LARGE_FILES value needed for large files... $ECHO_C" >&6
+if test "${ac_cv_sys_large_files+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ while :; do
+ ac_cv_sys_large_files=no
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+ We can't simply define LARGE_OFF_T to be 9223372036854775807,
+ since some C++ compilers masquerading as C compilers
+ incorrectly reject 9223372036854775807. */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+ && LARGE_OFF_T % 2147483647 == 1)
+ ? 1 : -1];
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#define _LARGE_FILES 1
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+ We can't simply define LARGE_OFF_T to be 9223372036854775807,
+ since some C++ compilers masquerading as C compilers
+ incorrectly reject 9223372036854775807. */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+ && LARGE_OFF_T % 2147483647 == 1)
+ ? 1 : -1];
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_sys_large_files=1; break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+ break
+done
+fi
+echo "$as_me:$LINENO: result: $ac_cv_sys_large_files" >&5
+echo "${ECHO_T}$ac_cv_sys_large_files" >&6
+if test "$ac_cv_sys_large_files" != no; then
+
+cat >>confdefs.h <<_ACEOF
+#define _LARGE_FILES $ac_cv_sys_large_files
+_ACEOF
+
+fi
+rm -f conftest*
+fi
+
+fi
# Select semaphore implementation type.
dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.194 2002/07/27 20:10:03 petere Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.195 2002/08/20 17:54:43 petere Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
[AC_CHECK_FUNCS(on_exit, [],
[AC_MSG_ERROR([neither atexit() nor on_exit() found])])])
+AC_FUNC_FSEEKO
+
# This test makes sure that run tests work at all. Sometimes a shared
# library is found by the linker, but the runtime linker can't find it.
PGAC_FUNC_POSIX_SIGNALS
+if test $ac_cv_func_fseeko = yes; then
+AC_SYS_LARGEFILE
+fi
# Select semaphore implementation type.
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.148 2002/08/19 19:33:34 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.149 2002/08/20 17:54:44 petere Exp $
-->
<appendix id="release">
worries about funny characters.
-->
<literallayout><![CDATA[
+Files larger than 2 GB are now supported (if supported by the operating system)
SERIAL no longer implies UNIQUE; specify explicitly if index is wanted
pg_dump -n and -N options have been removed. The new behavior is like -n but knows about key words.
CLUSTER is no longer hazardous to your schema
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.21 2002/08/18 09:36:25 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.22 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
DataDumperPtr dumpFn, void *dumpArg);
/* Called to write *data* to the archive */
-extern int WriteData(Archive *AH, const void *data, int dLen);
+extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
/*
extern int StartBlobs(Archive* AH);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.54 2002/08/18 09:36:25 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.55 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
*/
/* Public */
-int
-WriteData(Archive *AHX, const void *data, int dLen)
+size_t
+WriteData(Archive *AHX, const void *data, size_t dLen)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
(*AH->ArchiveEntryPtr) (AH, newToc);
/*
- * printf("New toc owned by '%s', oid %d\n", newToc->owner,
+ * printf("New toc owned by '%s', oid %u\n", newToc->owner,
* newToc->oidVal);
*/
}
if (AH->lo_buf_used > 0)
{
/* Write remaining bytes from the LO buffer */
- int res;
+ size_t res;
res = lo_write(AH->connection, AH->loFd, (void *) AH->lo_buf, AH->lo_buf_used);
- ahlog(AH, 5, "wrote remaining %d bytes of large object data (result = %d)\n",
- (int)AH->lo_buf_used, res);
+ ahlog(AH, 5, "wrote remaining %lu bytes of large object data (result = %lu)\n",
+ (unsigned long) AH->lo_buf_used, (unsigned long) res);
if (res != AH->lo_buf_used)
- die_horribly(AH, modulename, "could not write to large object (result: %d, expected: %d)\n",
- res, AH->lo_buf_used);
+ die_horribly(AH, modulename, "could not write to large object (result: %lu, expected: %lu)\n",
+ (unsigned long) res, (unsigned long) AH->lo_buf_used);
AH->lo_buf_used = 0;
}
int
ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
{
- int res;
+ size_t res;
if (AH->writingBlob)
{
- if(AH->lo_buf_used + size * nmemb > AH->lo_buf_size) {
- /* Split LO buffer */
- int remaining = AH->lo_buf_size - AH->lo_buf_used;
- int slack = nmemb * size - remaining;
-
- memcpy((char *)AH->lo_buf + AH->lo_buf_used, ptr, remaining);
- res = lo_write(AH->connection, AH->loFd, AH->lo_buf, AH->lo_buf_size);
- ahlog(AH, 5, "wrote %d bytes of large object data (result = %d)\n",
- AH->lo_buf_size, res);
- if (res != AH->lo_buf_size)
- die_horribly(AH, modulename, "could not write to large object (result: %d, expected: %d)\n",
- res, AH->lo_buf_size);
- memcpy(AH->lo_buf, (char *)ptr + remaining, slack);
- AH->lo_buf_used = slack;
- } else {
- /* LO Buffer is still large enough, buffer it */
- memcpy((char *)AH->lo_buf + AH->lo_buf_used, ptr, size * nmemb);
- AH->lo_buf_used += size * nmemb;
- }
-
- return size * nmemb;
+ if (AH->lo_buf_used + size * nmemb > AH->lo_buf_size)
+ {
+ /* Split LO buffer */
+ size_t remaining = AH->lo_buf_size - AH->lo_buf_used;
+ size_t slack = nmemb * size - remaining;
+
+ memcpy((char *)AH->lo_buf + AH->lo_buf_used, ptr, remaining);
+ res = lo_write(AH->connection, AH->loFd, AH->lo_buf, AH->lo_buf_size);
+ ahlog(AH, 5, "wrote %lu bytes of large object data (result = %lu)\n",
+ (unsigned long) AH->lo_buf_size, (unsigned long) res);
+ if (res != AH->lo_buf_size)
+ die_horribly(AH, modulename,
+ "could not write to large object (result: %lu, expected: %lu)\n",
+ (unsigned long) res, (unsigned long) AH->lo_buf_size);
+ memcpy(AH->lo_buf, (char *)ptr + remaining, slack);
+ AH->lo_buf_used = slack;
+ }
+ else
+ {
+ /* LO Buffer is still large enough, buffer it */
+ memcpy((char *)AH->lo_buf + AH->lo_buf_used, ptr, size * nmemb);
+ AH->lo_buf_used += size * nmemb;
+ }
+
+ return size * nmemb;
}
else if (AH->gzOut)
{
{
res = fwrite((void *) ptr, size, nmemb, AH->OF);
if (res != nmemb)
- die_horribly(AH, modulename, "could not write to output file (%d != %d)\n",
- res, (int) nmemb);
+ die_horribly(AH, modulename, "could not write to output file (%lu != %lu)\n",
+ (unsigned long) res, (unsigned long) nmemb);
return res;
}
}
return _tocEntryRequired(te, ropt);
}
-int
+size_t
WriteInt(ArchiveHandle *AH, int i)
{
int b;
return res;
}
-int
+size_t
WriteStr(ArchiveHandle *AH, const char *c)
{
- int res;
+ size_t res;
if (c)
{
{
FILE *fh;
char sig[6]; /* More than enough */
- int cnt;
+ size_t cnt;
int wantClose = 0;
#if 0
if (ferror(fh))
die_horribly(AH, modulename, "could not read input file: %s\n", strerror(errno));
else
- die_horribly(AH, modulename, "input file is too short (read %d, expected 5)\n", cnt);
+ die_horribly(AH, modulename, "input file is too short (read %lu, expected 5)\n",
+ (unsigned long) cnt);
}
/* Save it, just in case we need it later */
}
/* If we can't seek, then mark the header as read */
- if (fseek(fh, 0, SEEK_SET) != 0)
+ if (fseeko(fh, 0, SEEK_SET) != 0)
{
/*
* NOTE: Formats that use the looahead buffer can unset this in
AH->lookaheadLen = 0; /* Don't bother since we've reset the file */
#if 0
- write_msg(modulename, "read %d bytes into lookahead buffer\n", AH->lookaheadLen);
+ write_msg(modulename, "read %lu bytes into lookahead buffer\n",
+ (unsigned long) AH->lookaheadLen);
#endif
/* Close the file */
AH->intSize = (*AH->ReadBytePtr) (AH);
if (AH->intSize > 32)
- die_horribly(AH, modulename, "sanity check on integer size (%d) failed\n", AH->intSize);
+ die_horribly(AH, modulename, "sanity check on integer size (%lu) failed\n",
+ (unsigned long) AH->intSize);
if (AH->intSize > sizeof(int))
write_msg(modulename, "WARNING: archive was made on a machine with larger integers, some operations may fail\n");
for (i = 0; i <= AH->tocCount + 1; i++)
{
/*
- * printf("%d: %x (%x, %x) - %d\n", i, te, te->prev, te->next,
+ * printf("%d: %x (%x, %x) - %u\n", i, te, te->prev, te->next,
* te->oidVal);
*/
tea[i] = te;
for (i = 0; i <= AH->tocCount + 1; i++)
{
/*
- * printf("%d: %x (%x, %x) - %d\n", i, te, te->prev, te->next,
+ * printf("%d: %x (%x, %x) - %u\n", i, te, te->prev, te->next,
* te->oidVal);
*/
te = te->next;
Oid id2 = te2->maxOidVal;
int cmpval;
- /* printf("Comparing %d to %d\n", id1, id2); */
+ /* printf("Comparing %u to %u\n", id1, id2); */
cmpval = oidcmp(id1, id2);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.45 2002/08/10 16:57:31 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.46 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
{
void *next_in;
void *next_out;
- int avail_in;
- int avail_out;
+ size_t avail_in;
+ size_t avail_out;
} z_stream;
typedef z_stream *z_streamp;
#endif
typedef void (*ArchiveEntryPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*StartDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
-typedef int (*WriteDataPtr) (struct _archiveHandle * AH, const void *data, int dLen);
+typedef size_t (*WriteDataPtr) (struct _archiveHandle * AH, const void *data, size_t dLen);
typedef void (*EndDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*StartBlobsPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef int (*WriteBytePtr) (struct _archiveHandle * AH, const int i);
typedef int (*ReadBytePtr) (struct _archiveHandle * AH);
-typedef int (*WriteBufPtr) (struct _archiveHandle * AH, const void *c, int len);
-typedef int (*ReadBufPtr) (struct _archiveHandle * AH, void *buf, int len);
+typedef size_t (*WriteBufPtr) (struct _archiveHandle * AH, const void *c, size_t len);
+typedef size_t (*ReadBufPtr) (struct _archiveHandle * AH, void *buf, size_t len);
typedef void (*SaveArchivePtr) (struct _archiveHandle * AH);
typedef void (*WriteExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*ReadExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*PrintExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*PrintTocDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te, RestoreOptions *ropt);
-typedef int (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, int len);
+typedef size_t (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, size_t len);
typedef int (*TocSortCompareFn) (const void *te1, const void *te2);
int debugLevel; /* Used for logging (currently only by
* --verbose) */
- int intSize; /* Size of an integer in the archive */
+ size_t intSize; /* Size of an integer in the archive */
ArchiveFormat format; /* Archive format */
sqlparseInfo sqlparse;
* already */
char *lookahead; /* Buffer used when reading header to
* discover format */
- int lookaheadSize; /* Size of allocated buffer */
- int lookaheadLen; /* Length of data in lookahead */
- int lookaheadPos; /* Current read position in lookahead
+ size_t lookaheadSize; /* Size of allocated buffer */
+ size_t lookaheadLen; /* Length of data in lookahead */
+ off_t lookaheadPos; /* Current read position in lookahead
* buffer */
ArchiveEntryPtr ArchiveEntryPtr; /* Called for each metadata object */
RestoreOptions *ropt; /* Used to check restore options in
* ahwrite etc */
void *lo_buf;
- int lo_buf_used;
- int lo_buf_size;
+ size_t lo_buf_used;
+ size_t lo_buf_size;
} ArchiveHandle;
typedef struct _tocEntry
* Mandatory routines for each supported format
*/
-extern int WriteInt(ArchiveHandle *AH, int i);
+extern size_t WriteInt(ArchiveHandle *AH, int i);
extern int ReadInt(ArchiveHandle *AH);
extern char *ReadStr(ArchiveHandle *AH);
-extern int WriteStr(ArchiveHandle *AH, const char *s);
+extern size_t WriteStr(ArchiveHandle *AH, const char *s);
extern void StartRestoreBlobs(ArchiveHandle *AH);
extern void StartRestoreBlob(ArchiveHandle *AH, Oid oid);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.19 2002/05/29 01:38:56 tgl Exp $
- *
- * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
- *
- * Initial version.
- *
- * Modifications - 04-Jan-2001 - pjw@rhyme.com.au
- *
- * - Check results of IO routines more carefully.
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.20 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te);
static void _StartData(ArchiveHandle *AH, TocEntry *te);
-static int _WriteData(ArchiveHandle *AH, const void *data, int dLen);
+static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen);
static void _EndData(ArchiveHandle *AH, TocEntry *te);
static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *);
-static int _WriteBuf(ArchiveHandle *AH, const void *buf, int len);
-static int _ReadBuf(ArchiveHandle *AH, void *buf, int len);
+static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
+static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te);
z_streamp zp;
char *zlibOut;
char *zlibIn;
- int inSize;
+ size_t inSize;
int hasSeek;
- int filePos;
- int dataStart;
+ off_t filePos;
+ off_t dataStart;
} lclContext;
typedef struct
{
- int dataPos;
- int dataLen;
+ off_t dataPos;
+ size_t dataLen;
} lclTocEntry;
static void _readBlockHeader(ArchiveHandle *AH, int *type, int *id);
static void _StartDataCompressor(ArchiveHandle *AH, TocEntry *te);
static void _EndDataCompressor(ArchiveHandle *AH, TocEntry *te);
-static int _getFilePos(ArchiveHandle *AH, lclContext *ctx);
+static off_t _getFilePos(ArchiveHandle *AH, lclContext *ctx);
static int _DoDeflate(ArchiveHandle *AH, lclContext *ctx, int flush);
static char *modulename = gettext_noop("custom archiver");
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
AH->lo_buf = (void *)malloc(LOBBUFSIZE);
- if(AH->lo_buf == NULL)
- die_horribly(AH, modulename, "out of memory\n");
+ if (AH->lo_buf == NULL)
+ die_horribly(AH, modulename, "out of memory\n");
/*
* zlibOutSize is the buffer size we tell zlib it can output to. We
if (!AH->FH)
die_horribly(AH, modulename, "could not open archive file %s: %s\n", AH->fSpec, strerror(errno));
- ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
+ ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
}
else
if (!AH->FH)
die_horribly(AH, modulename, "could not open archive file %s: %s\n", AH->fSpec, strerror(errno));
- ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
+ ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
ReadHead(AH);
ReadToc(AH);
{
lclTocEntry *ctx = (lclTocEntry *) te->formatData;
- ahprintf(AH, "-- Data Pos: %d (Length %d)\n", ctx->dataPos, ctx->dataLen);
+ ahprintf(AH, "-- Data Pos: " INT64_FORMAT " (Length %lu)\n",
+ (int64) ctx->dataPos, (unsigned long) ctx->dataLen);
}
/*
* Mandatory.
*
*/
-static int
-_WriteData(ArchiveHandle *AH, const void *data, int dLen)
+static size_t
+_WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
{
lclContext *ctx = (lclContext *) AH->formatData;
z_streamp zp = ctx->zp;
while (zp->avail_in != 0)
{
- /* printf("Deflating %d bytes\n", dLen); */
+ /* printf("Deflating %lu bytes\n", (unsigned long) dLen); */
_DoDeflate(AH, ctx, 0);
}
return dLen;
/* Grab it */
- if (fseek(AH->FH, tctx->dataPos, SEEK_SET) != 0)
+ if (fseeko(AH->FH, tctx->dataPos, SEEK_SET) != 0)
die_horribly(AH, modulename, "error during file seek: %s\n", strerror(errno));
_readBlockHeader(AH, &blkType, &id);
{
lclContext *ctx = (lclContext *) AH->formatData;
z_streamp zp = ctx->zp;
- int blkLen;
+ size_t blkLen;
char *in = ctx->zlibIn;
- int cnt;
+ size_t cnt;
#ifdef HAVE_LIBZ
int res;
cnt = fread(in, 1, blkLen, AH->FH);
if (cnt != blkLen)
- die_horribly(AH, modulename, "could not read data block - expected %d, got %d\n", blkLen, cnt);
+ die_horribly(AH, modulename,
+ "could not read data block - expected %lu, got %lu\n",
+ (unsigned long) blkLen, (unsigned long) cnt);
ctx->filePos += blkLen;
_skipData(ArchiveHandle *AH)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int blkLen;
+ size_t blkLen;
char *in = ctx->zlibIn;
- int cnt;
+ size_t cnt;
blkLen = ReadInt(AH);
while (blkLen != 0)
}
cnt = fread(in, 1, blkLen, AH->FH);
if (cnt != blkLen)
- die_horribly(AH, modulename, "could not read data block - expected %d, got %d\n", blkLen, cnt);
+ die_horribly(AH, modulename,
+ "could not read data block - expected %lu, got %lu\n",
+ (unsigned long) blkLen, (unsigned long) cnt);
ctx->filePos += blkLen;
* These routines are only used to read & write headers & TOC.
*
*/
-static int
-_WriteBuf(ArchiveHandle *AH, const void *buf, int len)
+static size_t
+_WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int res;
+ size_t res;
res = fwrite(buf, 1, len, AH->FH);
if (res != len)
- die_horribly(AH, modulename, "write error in _WriteBuf (%d != %d)\n", res, len);
+ die_horribly(AH, modulename,
+ "write error in _WriteBuf (%lu != %lu)\n",
+ (unsigned long) res, (unsigned long) len);
ctx->filePos += res;
return res;
* These routines are only used to read & write headers & TOC.
*
*/
-static int
-_ReadBuf(ArchiveHandle *AH, void *buf, int len)
+static size_t
+_ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int res;
+ size_t res;
res = fread(buf, 1, len, AH->FH);
ctx->filePos += res;
_CloseArchive(ArchiveHandle *AH)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int tpos;
+ off_t tpos;
if (AH->mode == archModeWrite)
{
WriteHead(AH);
- tpos = ftell(AH->FH);
+ tpos = ftello(AH->FH);
WriteToc(AH);
ctx->dataStart = _getFilePos(AH, ctx);
WriteDataChunks(AH);
*/
if (ctx->hasSeek)
{
- fseek(AH->FH, tpos, SEEK_SET);
+ fseeko(AH->FH, tpos, SEEK_SET);
WriteToc(AH);
}
}
/*
* Get the current position in the archive file.
*/
-static int
+static off_t
_getFilePos(ArchiveHandle *AH, lclContext *ctx)
{
- int pos;
+ off_t pos;
if (ctx->hasSeek)
{
- pos = ftell(AH->FH);
+ pos = ftello(AH->FH);
if (pos != ctx->filePos)
{
write_msg(modulename, "WARNING: ftell mismatch with expected position -- ftell ignored\n");
if (zp->avail_out < zlibOutSize)
{
/*
- * printf("Wrote %d byte deflated chunk\n", zlibOutSize -
- * zp->avail_out);
+ * printf("Wrote %lu byte deflated chunk\n", (unsigned long) (zlibOutSize -
+ * zp->avail_out));
*/
WriteInt(AH, zlibOutSize - zp->avail_out);
if (fwrite(out, 1, zlibOutSize - zp->avail_out, AH->FH) != (zlibOutSize - zp->avail_out))
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.37 2002/08/18 09:36:25 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.38 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
-#include <unistd.h> /* for getopt() */
+#include <unistd.h>
#include <ctype.h>
#ifdef HAVE_TERMIOS_H
static char *
_sendCopyLine(ArchiveHandle *AH, char *qry, char *eos)
{
- int loc; /* Location of next newline */
+ size_t loc; /* Location of next newline */
int pos = 0; /* Current position */
int sPos = 0; /* Last pos of a slash char */
int isEnd = 0;
/* Convenience function to send one or more queries. Monitors result to handle COPY statements */
int
-ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, int bufLen)
+ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, size_t bufLen)
{
char *qry = (char *) qryv;
char *eos = qry + bufLen;
* Definitions for pg_backup_db.c
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.7 2002/05/29 01:38:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.8 2002/08/20 17:54:44 petere Exp $
*/
#define BLOB_XREF_TABLE "pg_dump_blob_xref" /* MUST be lower case */
extern void FixupBlobRefs(ArchiveHandle *AH, TocEntry *te);
extern int ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc, bool use_blob);
-extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qry, int bufLen);
+extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qry, size_t bufLen);
extern void CreateBlobXrefTable(ArchiveHandle *AH);
extern void InsertBlobXref(ArchiveHandle *AH, Oid old, Oid new);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.16 2002/05/29 01:38:56 tgl Exp $
- *
- * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
- *
- * Initial version.
- *
- * Modifications - 04-Jan-2001 - pjw@rhyme.com.au
- *
- * - Check results of IO routines more carefully.
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.17 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te);
static void _StartData(ArchiveHandle *AH, TocEntry *te);
-static int _WriteData(ArchiveHandle *AH, const void *data, int dLen);
+static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen);
static void _EndData(ArchiveHandle *AH, TocEntry *te);
static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *);
-static int _WriteBuf(ArchiveHandle *AH, const void *buf, int len);
-static int _ReadBuf(ArchiveHandle *AH, void *buf, int len);
+static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
+static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te);
typedef struct
{
int hasSeek;
- int filePos;
+ off_t filePos;
FILE *blobToc;
} lclContext;
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
AH->lo_buf = (void *)malloc(LOBBUFSIZE);
- if(AH->lo_buf == NULL)
- die_horribly(AH, modulename, "out of memory\n");
+ if (AH->lo_buf == NULL)
+ die_horribly(AH, modulename, "out of memory\n");
/*
* Now open the TOC file
if (AH->FH == NULL)
die_horribly(NULL, modulename, "could not open output file: %s\n", strerror(errno));
- ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
+ ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
if (AH->compression < 0 || AH->compression > 9)
AH->compression = Z_DEFAULT_COMPRESSION;
if (AH->FH == NULL)
die_horribly(NULL, modulename, "could not open input file: %s\n", strerror(errno));
- ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
+ ctx->hasSeek = (fseeko(AH->FH, 0, SEEK_CUR) == 0);
ReadHead(AH);
ReadToc(AH);
}
-static int
-_WriteData(ArchiveHandle *AH, const void *data, int dLen)
+static size_t
+_WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
{
lclTocEntry *tctx = (lclTocEntry *) AH->currToc->formatData;
_PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt)
{
char buf[4096];
- int cnt;
+ size_t cnt;
if (!filename)
return;
{
lclContext *ctx = (lclContext *) AH->formatData;
char blobTe[K_STD_BUF_SIZE];
- int fpos;
- int eos;
+ size_t fpos;
+ size_t eos;
if (fgets(&blobTe[0], K_STD_BUF_SIZE - 1, ctx->blobToc) != NULL)
{
return res;
}
-static int
-_WriteBuf(ArchiveHandle *AH, const void *buf, int len)
+static size_t
+_WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int res;
+ size_t res;
res = fwrite(buf, 1, len, AH->FH);
if (res != len)
return res;
}
-static int
-_ReadBuf(ArchiveHandle *AH, void *buf, int len)
+static size_t
+_ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int res;
+ size_t res;
res = fread(buf, 1, len, AH->FH);
ctx->filePos += res;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.9 2002/05/10 22:36:26 tgl Exp $
- *
- * Modifications - 09-Jul-2000 - pjw@rhyme.com.au
- *
- * Initial version.
- *
- * Modifications - 04-Jan-2001 - pjw@rhyme.com.au
- *
- * - Check results of IO routines more carefully.
- *
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.10 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include <string.h>
#include <unistd.h> /* for dup */
-static int _WriteData(ArchiveHandle *AH, const void *data, int dLen);
+static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen);
static void _EndData(ArchiveHandle *AH, TocEntry *te);
static int _WriteByte(ArchiveHandle *AH, const int i);
-static int _WriteBuf(ArchiveHandle *AH, const void *buf, int len);
+static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
* As at V1.3, this is only called for COPY FROM dfata, and BLOB data
*------
*/
-static int
-_WriteData(ArchiveHandle *AH, const void *data, int dLen)
+static size_t
+_WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
{
/* Just send it to output */
ahwrite(data, 1, dLen, AH);
return 0;
}
-static int
-_WriteBuf(ArchiveHandle *AH, const void *buf, int len)
+static size_t
+_WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
{
/* Don't do anything */
return len;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.24 2002/07/04 15:35:07 momjian Exp $
- *
- * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
- *
- * Initial version.
- *
- * Modifications - 04-Jan-2001 - pjw@rhyme.com.au
- *
- * - Check results of IO routines more carefully.
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.25 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te);
static void _StartData(ArchiveHandle *AH, TocEntry *te);
-static int _WriteData(ArchiveHandle *AH, const void *data, int dLen);
+static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen);
static void _EndData(ArchiveHandle *AH, TocEntry *te);
static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *);
-static int _WriteBuf(ArchiveHandle *AH, const void *buf, int len);
-static int _ReadBuf(ArchiveHandle *AH, void *buf, int len);
+static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
+static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te);
FILE *tmpFH;
char *targetFile;
char mode;
- int pos;
- int fileLen;
+ off_t pos;
+ off_t fileLen;
ArchiveHandle *AH;
} TAR_MEMBER;
typedef struct
{
int hasSeek;
- int filePos;
+ off_t filePos;
TAR_MEMBER *blobToc;
FILE *tarFH;
- int tarFHpos;
- int tarNextMember;
+ off_t tarFHpos;
+ off_t tarNextMember;
TAR_MEMBER *FH;
int isSpecialScript;
TAR_MEMBER *scriptTH;
static void tarClose(ArchiveHandle *AH, TAR_MEMBER *TH);
#ifdef __NOT_USED__
-static char *tarGets(char *buf, int len, TAR_MEMBER *th);
+static char *tarGets(char *buf, size_t len, TAR_MEMBER *th);
#endif
static int tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...);
static void _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th);
static int _tarChecksum(char *th);
static TAR_MEMBER *_tarPositionTo(ArchiveHandle *AH, const char *filename);
-static int tarRead(void *buf, int len, TAR_MEMBER *th);
-static int tarWrite(const void *buf, int len, TAR_MEMBER *th);
+static size_t tarRead(void *buf, size_t len, TAR_MEMBER *th);
+static size_t tarWrite(const void *buf, size_t len, TAR_MEMBER *th);
static void _tarWriteHeader(TAR_MEMBER *th);
static int _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th);
-static int _tarReadRaw(ArchiveHandle *AH, void *buf, int len, TAR_MEMBER *th, FILE *fh);
+static size_t _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh);
-static int _scriptOut(ArchiveHandle *AH, const void *buf, int len);
+static size_t _scriptOut(ArchiveHandle *AH, const void *buf, size_t len);
/*
* Initializer
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
AH->lo_buf = (void *)malloc(LOBBUFSIZE);
- if(AH->lo_buf == NULL)
- die_horribly(AH, modulename, "out of memory\n");
+ if (AH->lo_buf == NULL)
+ die_horribly(AH, modulename, "out of memory\n");
/*
* Now open the TOC file
*/
/* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
- ctx->hasSeek = (fseek(ctx->tarFH, 0, SEEK_CUR) == 0);
+ ctx->hasSeek = (fseeko(ctx->tarFH, 0, SEEK_CUR) == 0);
if (AH->compression < 0 || AH->compression > 9)
AH->compression = Z_DEFAULT_COMPRESSION;
ctx->tarFHpos = 0;
- ctx->hasSeek = (fseek(ctx->tarFH, 0, SEEK_CUR) == 0);
+ ctx->hasSeek = (fseeko(ctx->tarFH, 0, SEEK_CUR) == 0);
/*
* Forcibly unmark the header as read since we use the lookahead
#ifdef __NOT_USED__
static char *
-tarGets(char *buf, int len, TAR_MEMBER *th)
+tarGets(char *buf, size_t len, TAR_MEMBER *th)
{
char *s;
- int cnt = 0;
+ size_t cnt = 0;
char c = ' ';
int eof = 0;
* Just read bytes from the archive. This is the low level read routine
* that is used for ALL reads on a tar file.
*/
-static int
-_tarReadRaw(ArchiveHandle *AH, void *buf, int len, TAR_MEMBER *th, FILE *fh)
+static size_t
+_tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int avail;
- int used = 0;
- int res = 0;
+ size_t avail;
+ size_t used = 0;
+ size_t res = 0;
avail = AH->lookaheadLen - AH->lookaheadPos;
if (avail > 0)
return (res + used);
}
-static int
-tarRead(void *buf, int len, TAR_MEMBER *th)
+static size_t
+tarRead(void *buf, size_t len, TAR_MEMBER *th)
{
- int res;
+ size_t res;
if (th->pos + len > th->fileLen)
len = th->fileLen - th->pos;
return res;
}
-static int
-tarWrite(const void *buf, int len, TAR_MEMBER *th)
+static size_t
+tarWrite(const void *buf, size_t len, TAR_MEMBER *th)
{
- int res;
+ size_t res;
if (th->zFH != 0)
res = GZWRITE((void *) buf, 1, len, th->zFH);
if (res != len)
die_horribly(th->AH, modulename,
- "could not write to tar member (wrote %d, attempted %d)\n", res, len);
+ "could not write to tar member (wrote %lu, attempted %lu)\n",
+ (unsigned long) res, (unsigned long) len);
th->pos += res;
return res;
}
-static int
-_WriteData(ArchiveHandle *AH, const void *data, int dLen)
+static size_t
+_WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
{
lclTocEntry *tctx = (lclTocEntry *) AH->currToc->formatData;
{
lclContext *ctx = (lclContext *) AH->formatData;
char buf[4096];
- int cnt;
+ size_t cnt;
TAR_MEMBER *th;
if (!filename)
lclContext *ctx = (lclContext *) AH->formatData;
lclTocEntry *tctx = (lclTocEntry *) te->formatData;
char *tmpCopy;
- int i,
+ size_t i,
pos1,
pos2;
if (pos2 >= strlen(tmpCopy))
die_horribly(AH, modulename,
- "bad COPY statement - could not find \"from stdin\" in string \"%s\" starting at position %d\n",
- tmpCopy, pos1);
+ "bad COPY statement - could not find \"from stdin\" in string \"%s\" starting at position %lu\n",
+ tmpCopy, (unsigned long) pos1);
ahwrite(tmpCopy, 1, pos2, AH); /* 'copy "table" [with oids]' */
ahprintf(AH, " from '$$PATH$$/%s' %s", tctx->filename, &tmpCopy[pos2 + 10]);
Oid oid;
lclContext *ctx = (lclContext *) AH->formatData;
TAR_MEMBER *th;
- int cnt;
+ size_t cnt;
char buf[4096];
StartRestoreBlobs(AH);
return c;
}
-static int
-_WriteBuf(ArchiveHandle *AH, const void *buf, int len)
+static size_t
+_WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int res;
+ size_t res;
res = tarWrite((void *) buf, len, ctx->FH);
ctx->filePos += res;
return res;
}
-static int
-_ReadBuf(ArchiveHandle *AH, void *buf, int len)
+static size_t
+_ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int res;
+ size_t res;
res = tarRead(buf, len, ctx->FH);
ctx->filePos += res;
AH->FH = NULL;
}
-static int
-_scriptOut(ArchiveHandle *AH, const void *buf, int len)
+static size_t
+_scriptOut(ArchiveHandle *AH, const void *buf, size_t len)
{
lclContext *ctx = (lclContext *) AH->formatData;
{
char *p = NULL;
va_list ap;
- int bSize = strlen(fmt) + 256; /* Should be enough */
+ size_t bSize = strlen(fmt) + 256; /* Should be enough */
int cnt = -1;
/*
lclContext *ctx = (lclContext *) AH->formatData;
FILE *tmp = th->tmpFH; /* Grab it for convenience */
char buf[32768];
- int cnt;
- int len = 0;
- int res;
- int i,
+ size_t cnt;
+ off_t len = 0;
+ size_t res;
+ size_t i,
pad;
/*
* Find file len & go back to start.
*/
- fseek(tmp, 0, SEEK_END);
- th->fileLen = ftell(tmp);
- fseek(tmp, 0, SEEK_SET);
+ fseeko(tmp, 0, SEEK_END);
+ th->fileLen = ftello(tmp);
+ fseeko(tmp, 0, SEEK_SET);
_tarWriteHeader(th);
{
res = fwrite(&buf[0], 1, cnt, th->tarFH);
if (res != cnt)
- die_horribly(AH, modulename, "write error appending to tar archive (wrote %d, attempted %d)\n", res, cnt);
+ die_horribly(AH, modulename,
+ "write error appending to tar archive (wrote %lu, attempted %lu)\n",
+ (unsigned long) res, (unsigned long) cnt);
len += res;
}
die_horribly(AH, modulename, "could not close tar member: %s\n", strerror(errno));
if (len != th->fileLen)
- die_horribly(AH, modulename, "actual file length (%d) does not match expected (%d)\n",
- len, th->pos);
+ die_horribly(AH, modulename, "actual file length (" INT64_FORMAT ") does not match expected (" INT64_FORMAT ")\n",
+ (int64) len, (int64) th->pos);
pad = ((len + 511) & ~511) - len;
for (i = 0; i < pad; i++)
TAR_MEMBER *th = calloc(1, sizeof(TAR_MEMBER));
char c;
char header[512];
- int i,
+ size_t i,
len,
- blks,
- id;
+ blks;
+ int id;
th->AH = AH;
/* Go to end of current file, if any */
if (ctx->tarFHpos != 0)
{
- ahlog(AH, 4, "moving from position %d (%x) to next member at file position %d (%x)\n",
- ctx->tarFHpos, ctx->tarFHpos,
- ctx->tarNextMember, ctx->tarNextMember);
+ ahlog(AH, 4, "moving from position " INT64_FORMAT " to next member at file position " INT64_FORMAT "\n",
+ (int64) ctx->tarFHpos, (int64) ctx->tarNextMember);
while (ctx->tarFHpos < ctx->tarNextMember)
_tarReadRaw(AH, &c, 1, NULL, ctx->tarFH);
}
- ahlog(AH, 4, "now at file position %d (%x)\n", ctx->tarFHpos, ctx->tarFHpos);
+ ahlog(AH, 4, "now at file position " INT64_FORMAT "\n", (int64) ctx->tarFHpos);
/* We are at the start of the file. or at the next member */
char tag[100];
int sum,
chk;
- int len;
- int hPos;
+ size_t len;
+ off_t hPos;
int i;
bool gotBlock = false;
while (!gotBlock)
{
#if 0
- if (ftell(ctx->tarFH) != ctx->tarFHpos)
+ if (ftello(ctx->tarFH) != ctx->tarFHpos)
die_horribly(AH, modulename,
- "mismatch in actual vs. predicted file position (%d vs. %d)\n",
- ftell(ctx->tarFH), ctx->tarFHpos);
+ "mismatch in actual vs. predicted file position (" INT64_FORMAT " vs. " INT64_FORMAT ")\n",
+ (int64) ftello(ctx->tarFH), (int64) ctx->tarFHpos);
#endif
/* Save the pos for reporting purposes */
return 0;
if (len != 512)
- die_horribly(AH, modulename, "incomplete tar header found (%d bytes)\n", len);
+ die_horribly(AH, modulename,
+ "incomplete tar header found (%lu bytes)\n",
+ (unsigned long) len);
/* Calc checksum */
chk = _tarChecksum(&h[0]);
sscanf(&h[124], "%12o", &len);
sscanf(&h[148], "%8o", &sum);
- ahlog(AH, 3, "TOC Entry %s at %d (length %d, checksum %d)\n", &tag[0], hPos, len, sum);
+ ahlog(AH, 3, "TOC Entry %s at " INT64_FORMAT " (length %lu, checksum %d)\n",
+ &tag[0], (int64) hPos, (unsigned long) len, sum);
if (chk != sum)
die_horribly(AH, modulename,
"corrupt tar header found in %s "
- "(expected %d (%o), computed %d (%o)) file position %ld (%lx)\n",
- &tag[0], sum, sum, chk, chk, ftell(ctx->tarFH), ftell(ctx->tarFH));
+ "(expected %d, computed %d) file position " INT64_FORMAT "\n",
+ &tag[0], sum, chk, (int64) ftello(ctx->tarFH));
th->targetFile = strdup(tag);
th->fileLen = len;
sprintf(&h[116], " 02000 ");
/* File size 12 */
- sprintf(&h[124], "%10o ", th->fileLen);
+ /* FIXME: This goes only up to 2^30. -- What about larger files? */
+ sprintf(&h[124], "%10o ", (unsigned int) th->fileLen);
/* Mod Time 12 */
sprintf(&h[136], "%10o ", (int) time(NULL));
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.287 2002/08/19 19:33:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.288 2002/08/20 17:54:44 petere Exp $
*
*-------------------------------------------------------------------------
*/
int i;
int loFd;
char buf[loBufSize];
- int cnt;
+ size_t cnt;
Oid blobOid;
if (g_verbose)
* or in pg_config.h afterwards. Of course, if you edit pg_config.h, then your
* changes will be overwritten the next time you run configure.
*
- * $Id: pg_config.h.in,v 1.27 2002/08/13 20:40:44 momjian Exp $
+ * $Id: pg_config.h.in,v 1.28 2002/08/20 17:54:45 petere Exp $
*/
#ifndef PG_CONFIG_H
/* Define exactly one of these symbols to select shared-mem implementation */
#undef USE_SYSV_SHARED_MEMORY
+/* Define to 1 to make fseeko visible on some hosts. */
+#undef _LARGEFILE_SOURCE
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#undef HAVE_FSEEKO
+
+#ifndef HAVE_FSEEKO
+#define fseeko(a, b, c) fseek((a), (b), (c))
+#define ftello(a) ftell((a))
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#undef _FILE_OFFSET_BITS
+
+/* Define for large files, on AIX-style hosts. */
+#undef _LARGE_FILES
+
/*
*------------------------------------------------------------------------