1515 *
1616 *
1717 * IDENTIFICATION
18- *$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.54 2002/08/18 09:36:25 petere Exp $
18+ *$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.55 2002/08/20 17:54:44 petere Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
@@ -581,8 +581,8 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt
581581 */
582582
583583/* Public */
584- int
585- WriteData (Archive * AHX ,const void * data ,int dLen )
584+ size_t
585+ WriteData (Archive * AHX ,const void * data ,size_t dLen )
586586{
587587ArchiveHandle * AH = (ArchiveHandle * )AHX ;
588588
@@ -646,7 +646,7 @@ ArchiveEntry(Archive *AHX, const char *oid, const char *tag,
646646(* AH -> ArchiveEntryPtr ) (AH ,newToc );
647647
648648/*
649- * printf("New toc owned by '%s', oid %d \n", newToc->owner,
649+ * printf("New toc owned by '%s', oid %u \n", newToc->owner,
650650 * newToc->oidVal);
651651 */
652652}
@@ -814,15 +814,15 @@ EndRestoreBlob(ArchiveHandle *AH, Oid oid)
814814if (AH -> lo_buf_used > 0 )
815815{
816816/* Write remaining bytes from the LO buffer */
817- int res ;
817+ size_t res ;
818818
819819res = lo_write (AH -> connection ,AH -> loFd , (void * )AH -> lo_buf ,AH -> lo_buf_used );
820820
821- ahlog (AH ,5 ,"wrote remaining %d bytes of large object data (result = %d )\n" ,
822- (int ) AH -> lo_buf_used ,res );
821+ ahlog (AH ,5 ,"wrote remaining %lu bytes of large object data (result = %lu )\n" ,
822+ (unsigned long ) AH -> lo_buf_used , ( unsigned long ) res );
823823if (res != AH -> lo_buf_used )
824- die_horribly (AH ,modulename ,"could not write to large object (result: %d , expected: %d )\n" ,
825- res ,AH -> lo_buf_used );
824+ die_horribly (AH ,modulename ,"could not write to large object (result: %lu , expected: %lu )\n" ,
825+ ( unsigned long ) res , ( unsigned long ) AH -> lo_buf_used );
826826AH -> lo_buf_used = 0 ;
827827}
828828
@@ -1202,31 +1202,35 @@ RestoringToDB(ArchiveHandle *AH)
12021202int
12031203ahwrite (const void * ptr ,size_t size ,size_t nmemb ,ArchiveHandle * AH )
12041204{
1205- int res ;
1205+ size_t res ;
12061206
12071207if (AH -> writingBlob )
12081208{
1209- if (AH -> lo_buf_used + size * nmemb > AH -> lo_buf_size ) {
1210- /* Split LO buffer */
1211- int remaining = AH -> lo_buf_size - AH -> lo_buf_used ;
1212- int slack = nmemb * size - remaining ;
1213-
1214- memcpy ((char * )AH -> lo_buf + AH -> lo_buf_used ,ptr ,remaining );
1215- res = lo_write (AH -> connection ,AH -> loFd ,AH -> lo_buf ,AH -> lo_buf_size );
1216- ahlog (AH ,5 ,"wrote %d bytes of large object data (result = %d)\n" ,
1217- AH -> lo_buf_size ,res );
1218- if (res != AH -> lo_buf_size )
1219- die_horribly (AH ,modulename ,"could not write to large object (result: %d, expected: %d)\n" ,
1220- res ,AH -> lo_buf_size );
1221- memcpy (AH -> lo_buf , (char * )ptr + remaining ,slack );
1222- AH -> lo_buf_used = slack ;
1223- }else {
1224- /* LO Buffer is still large enough, buffer it */
1225- memcpy ((char * )AH -> lo_buf + AH -> lo_buf_used ,ptr ,size * nmemb );
1226- AH -> lo_buf_used += size * nmemb ;
1227- }
1228-
1229- return size * nmemb ;
1209+ if (AH -> lo_buf_used + size * nmemb > AH -> lo_buf_size )
1210+ {
1211+ /* Split LO buffer */
1212+ size_t remaining = AH -> lo_buf_size - AH -> lo_buf_used ;
1213+ size_t slack = nmemb * size - remaining ;
1214+
1215+ memcpy ((char * )AH -> lo_buf + AH -> lo_buf_used ,ptr ,remaining );
1216+ res = lo_write (AH -> connection ,AH -> loFd ,AH -> lo_buf ,AH -> lo_buf_size );
1217+ ahlog (AH ,5 ,"wrote %lu bytes of large object data (result = %lu)\n" ,
1218+ (unsigned long )AH -> lo_buf_size , (unsigned long )res );
1219+ if (res != AH -> lo_buf_size )
1220+ die_horribly (AH ,modulename ,
1221+ "could not write to large object (result: %lu, expected: %lu)\n" ,
1222+ (unsigned long )res , (unsigned long )AH -> lo_buf_size );
1223+ memcpy (AH -> lo_buf , (char * )ptr + remaining ,slack );
1224+ AH -> lo_buf_used = slack ;
1225+ }
1226+ else
1227+ {
1228+ /* LO Buffer is still large enough, buffer it */
1229+ memcpy ((char * )AH -> lo_buf + AH -> lo_buf_used ,ptr ,size * nmemb );
1230+ AH -> lo_buf_used += size * nmemb ;
1231+ }
1232+
1233+ return size * nmemb ;
12301234}
12311235else if (AH -> gzOut )
12321236{
@@ -1255,8 +1259,8 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
12551259{
12561260res = fwrite ((void * )ptr ,size ,nmemb ,AH -> OF );
12571261if (res != nmemb )
1258- die_horribly (AH ,modulename ,"could not write to output file (%d != %d )\n" ,
1259- res , (int )nmemb );
1262+ die_horribly (AH ,modulename ,"could not write to output file (%lu != %lu )\n" ,
1263+ ( unsigned long ) res , (unsigned long )nmemb );
12601264return res ;
12611265}
12621266}
@@ -1376,7 +1380,7 @@ TocIDRequired(ArchiveHandle *AH, int id, RestoreOptions *ropt)
13761380return _tocEntryRequired (te ,ropt );
13771381}
13781382
1379- int
1383+ size_t
13801384WriteInt (ArchiveHandle * AH ,int i )
13811385{
13821386int b ;
@@ -1434,10 +1438,10 @@ ReadInt(ArchiveHandle *AH)
14341438return res ;
14351439}
14361440
1437- int
1441+ size_t
14381442WriteStr (ArchiveHandle * AH ,const char * c )
14391443{
1440- int res ;
1444+ size_t res ;
14411445
14421446if (c )
14431447{
@@ -1477,7 +1481,7 @@ _discoverArchiveFormat(ArchiveHandle *AH)
14771481{
14781482FILE * fh ;
14791483char sig [6 ];/* More than enough */
1480- int cnt ;
1484+ size_t cnt ;
14811485int wantClose = 0 ;
14821486
14831487#if 0
@@ -1510,7 +1514,8 @@ _discoverArchiveFormat(ArchiveHandle *AH)
15101514if (ferror (fh ))
15111515die_horribly (AH ,modulename ,"could not read input file: %s\n" ,strerror (errno ));
15121516else
1513- die_horribly (AH ,modulename ,"input file is too short (read %d, expected 5)\n" ,cnt );
1517+ die_horribly (AH ,modulename ,"input file is too short (read %lu, expected 5)\n" ,
1518+ (unsigned long )cnt );
15141519}
15151520
15161521/* Save it, just in case we need it later */
@@ -1563,7 +1568,7 @@ _discoverArchiveFormat(ArchiveHandle *AH)
15631568}
15641569
15651570/* If we can't seek, then mark the header as read */
1566- if (fseek (fh ,0 ,SEEK_SET )!= 0 )
1571+ if (fseeko (fh ,0 ,SEEK_SET )!= 0 )
15671572{
15681573/*
15691574 * NOTE: Formats that use the looahead buffer can unset this in
@@ -1575,7 +1580,8 @@ _discoverArchiveFormat(ArchiveHandle *AH)
15751580AH -> lookaheadLen = 0 ;/* Don't bother since we've reset the file */
15761581
15771582#if 0
1578- write_msg (modulename ,"read %d bytes into lookahead buffer\n" ,AH -> lookaheadLen );
1583+ write_msg (modulename ,"read %lu bytes into lookahead buffer\n" ,
1584+ (unsigned long )AH -> lookaheadLen );
15791585#endif
15801586
15811587/* Close the file */
@@ -2305,7 +2311,8 @@ ReadHead(ArchiveHandle *AH)
23052311
23062312AH -> intSize = (* AH -> ReadBytePtr ) (AH );
23072313if (AH -> intSize > 32 )
2308- die_horribly (AH ,modulename ,"sanity check on integer size (%d) failed\n" ,AH -> intSize );
2314+ die_horribly (AH ,modulename ,"sanity check on integer size (%lu) failed\n" ,
2315+ (unsigned long )AH -> intSize );
23092316
23102317if (AH -> intSize > sizeof (int ))
23112318write_msg (modulename ,"WARNING: archive was made on a machine with larger integers, some operations may fail\n" );
@@ -2368,7 +2375,7 @@ _SortToc(ArchiveHandle *AH, TocSortCompareFn fn)
23682375for (i = 0 ;i <=AH -> tocCount + 1 ;i ++ )
23692376{
23702377/*
2371- * printf("%d: %x (%x, %x) - %d \n", i, te, te->prev, te->next,
2378+ * printf("%d: %x (%x, %x) - %u \n", i, te, te->prev, te->next,
23722379 * te->oidVal);
23732380 */
23742381tea [i ]= te ;
@@ -2390,7 +2397,7 @@ _SortToc(ArchiveHandle *AH, TocSortCompareFn fn)
23902397for (i = 0 ;i <=AH -> tocCount + 1 ;i ++ )
23912398{
23922399/*
2393- * printf("%d: %x (%x, %x) - %d \n", i, te, te->prev, te->next,
2400+ * printf("%d: %x (%x, %x) - %u \n", i, te, te->prev, te->next,
23942401 * te->oidVal);
23952402 */
23962403te = te -> next ;
@@ -2410,7 +2417,7 @@ _tocSortCompareByOIDNum(const void *p1, const void *p2)
24102417Oid id2 = te2 -> maxOidVal ;
24112418int cmpval ;
24122419
2413- /* printf("Comparing %d to %d \n", id1, id2); */
2420+ /* printf("Comparing %u to %u \n", id1, id2); */
24142421
24152422cmpval = oidcmp (id1 ,id2 );
24162423