8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 768fb00 commit 14ea893Copy full SHA for 14ea893
src/bin/pg_dump/compress_io.c
@@ -86,14 +86,14 @@ static void InitCompressorZlib(CompressorState *cs, int level);
86
static void DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs,
87
bool flush);
88
static void ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF);
89
-static size_t WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs,
+static void WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs,
90
const char *data, size_t dLen);
91
static void EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs);
92
#endif
93
94
/* Routines that support uncompressed data I/O */
95
static void ReadDataFromArchiveNone(ArchiveHandle *AH, ReadFunc readF);
96
-static size_t WriteDataToArchiveNone(ArchiveHandle *AH, CompressorState *cs,
+static void WriteDataToArchiveNone(ArchiveHandle *AH, CompressorState *cs,
97
98
99
/*
@@ -179,7 +179,7 @@ ReadDataFromArchive(ArchiveHandle *AH, int compression, ReadFunc readF)
179
180
* Compress and write data to the output stream (via writeF).
181
*/
182
-size_t
+void
183
WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
184
const void *data, size_t dLen)
185
{
@@ -190,14 +190,16 @@ WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
190
191
case COMPR_ALG_LIBZ:
192
#ifdef HAVE_LIBZ
193
- return WriteDataToArchiveZlib(AH, cs, data, dLen);
+ WriteDataToArchiveZlib(AH, cs, data, dLen);
194
#else
195
exit_horribly(modulename, "not built with zlib support\n");
196
197
+ break;
198
case COMPR_ALG_NONE:
- return WriteDataToArchiveNone(AH, cs, data, dLen);
199
+ WriteDataToArchiveNone(AH, cs, data, dLen);
200
201
}
- return 0; /* keep compiler quiet */
202
+ return;
203
204
205
@@ -298,10 +300,7 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
298
300
299
301
size_t len = cs->zlibOutSize - zp->avail_out;
302
- if (cs->writeF(AH, out, len) != len)
- exit_horribly(modulename,
303
- "could not write to output file: %s\n",
304
- strerror(errno));
+ cs->writeF(AH, out, len);
305
306
zp->next_out = (void *) out;
307
zp->avail_out = cs->zlibOutSize;
@@ -312,19 +311,15 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
312
311
313
314
315
-static size_t
+static void
316
WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs,
317
const char *data, size_t dLen)
318
319
cs->zp->next_in = (void *) data;
320
cs->zp->avail_in = dLen;
321
DeflateCompressorZlib(AH, cs, false);
322
323
- /*
324
- * we have either succeeded in writing dLen bytes or we have called
325
- * exit_horribly()
326
- */
327
- return dLen;
328
329
330
static void
@@ -427,19 +422,12 @@ ReadDataFromArchiveNone(ArchiveHandle *AH, ReadFunc readF)
427
422
free(buf);
428
423
429
424
430
425
431
426
WriteDataToArchiveNone(ArchiveHandle *AH, CompressorState *cs,
432
433
434
435
- * Any write function should do its own error checking but to make sure we
436
- * do a check here as well...
437
438
- if (cs->writeF(AH, data, dLen) != dLen)
439
440
441
442
+ cs->writeF(AH, data, dLen);
443
444
445
@@ -573,12 +561,27 @@ cfopen(const char *path, const char *mode, int compression)
573
561
int
574
562
cfread(void *ptr, int size, cfp *fp)
575
563
564
+ int ret;
565
+
566
+ if (size == 0)
567
+ return 0;
568
576
569
577
570
if (fp->compressedfp)
578
- return gzread(fp->compressedfp, ptr, size);
571
+ {
572
+ ret = gzread(fp->compressedfp, ptr, size);
+ if (ret != size && !gzeof(fp->compressedfp))
+ exit_horribly(modulename,
+ "could not read from input file: %s\n", strerror(errno));
+ }
579
else
580
581
- return fread(ptr, 1, size, fp->uncompressedfp);
+ ret = fread(ptr, 1, size, fp->uncompressedfp);
+ if (ret != size && !feof(fp->uncompressedfp))
582
+ READ_ERROR_EXIT(fp->uncompressedfp);
583
584
+ return ret;
585
586
587
@@ -595,12 +598,31 @@ cfwrite(const void *ptr, int size, cfp *fp)
595
598
596
599
cfgetc(cfp *fp)
597
600
601
602
603
604
- return gzgetc(fp->compressedfp);
605
606
+ ret = gzgetc(fp->compressedfp);
607
+ if (ret == EOF)
608
609
+ if (!gzeof(fp->compressedfp))
610
611
612
+ else
613
614
+ "could not read from input file: end of file\n");
615
616
617
618
- return fgetc(fp->uncompressedfp);
619
620
+ ret = fgetc(fp->uncompressedfp);
621
622
623
624
625
626
627
628
char *
src/bin/pg_dump/compress_io.h
@@ -29,7 +29,7 @@ typedef enum
29
} CompressionAlgorithm;
30
31
/* Prototype for callback function to WriteDataToArchive() */
32
-typedef size_t (*WriteFunc) (ArchiveHandle *AH, const char *buf, size_t len);
+typedef void (*WriteFunc) (ArchiveHandle *AH, const char *buf, size_t len);
33
34
35
* Prototype for callback function to ReadDataFromArchive()
@@ -50,7 +50,7 @@ typedef struct CompressorState CompressorState;
50
extern CompressorState *AllocateCompressor(int compression, WriteFunc writeF);
51
extern void ReadDataFromArchive(ArchiveHandle *AH, int compression,
52
ReadFunc readF);
53
-extern size_t WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
+extern void WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
54
const void *data, size_t dLen);
55
extern void EndCompressor(ArchiveHandle *AH, CompressorState *cs);
56
src/bin/pg_dump/pg_backup.h
@@ -180,7 +180,7 @@ extern void ArchiveEntry(Archive *AHX,
DataDumperPtr dumpFn, void *dumpArg);
/* Called to write *data* to the archive */
-extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
+extern void WriteData(Archive *AH, const void *data, size_t dLen);
extern int StartBlob(Archive *AH, Oid oid);
186
extern int EndBlob(Archive *AH, Oid oid);
@@ -208,7 +208,7 @@ extern RestoreOptions *NewRestoreOptions(void);
208
extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
209
210
/* Convenience functions used only when writing DATA */
211
-extern int archputs(const char *s, Archive *AH);
+extern void archputs(const char *s, Archive *AH);
212
extern int
213
archprintf(Archive *AH, const char *fmt,...)
214
/* This extension allows gcc to check the format string */