PostgreSQL Source Code  git master
compress_none.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include "compress_none.h"
#include "pg_backup_utils.h"
Include dependency graph for compress_none.c:

Go to the source code of this file.

Functions

static void ReadDataFromArchiveNone (ArchiveHandle *AH, CompressorState *cs)
 
static void WriteDataToArchiveNone (ArchiveHandle *AH, CompressorState *cs, const void *data, size_t dLen)
 
static void EndCompressorNone (ArchiveHandle *AH, CompressorState *cs)
 
void InitCompressorNone (CompressorState *cs, const pg_compress_specification compression_spec)
 
static bool read_none (void *ptr, size_t size, size_t *rsize, CompressFileHandle *CFH)
 
static bool write_none (const void *ptr, size_t size, CompressFileHandle *CFH)
 
static const char * get_error_none (CompressFileHandle *CFH)
 
static char * gets_none (char *ptr, int size, CompressFileHandle *CFH)
 
static int getc_none (CompressFileHandle *CFH)
 
static bool close_none (CompressFileHandle *CFH)
 
static bool eof_none (CompressFileHandle *CFH)
 
static bool open_none (const char *path, int fd, const char *mode, CompressFileHandle *CFH)
 
static bool open_write_none (const char *path, const char *mode, CompressFileHandle *CFH)
 
void InitCompressFileHandleNone (CompressFileHandle *CFH, const pg_compress_specification compression_spec)
 

Function Documentation

◆ close_none()

static bool close_none ( CompressFileHandle CFH)
static

Definition at line 148 of file compress_none.c.

149 {
150  FILE *fp = (FILE *) CFH->private_data;
151  int ret = 0;
152 
153  CFH->private_data = NULL;
154 
155  if (fp)
156  ret = fclose(fp);
157 
158  return ret == 0;
159 }
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76

References if(), and CompressFileHandle::private_data.

Referenced by InitCompressFileHandleNone().

◆ EndCompressorNone()

static void EndCompressorNone ( ArchiveHandle AH,
CompressorState cs 
)
static

Definition at line 56 of file compress_none.c.

57 {
58  /* no op */
59 }

Referenced by InitCompressorNone().

◆ eof_none()

static bool eof_none ( CompressFileHandle CFH)
static

Definition at line 162 of file compress_none.c.

163 {
164  return feof((FILE *) CFH->private_data) != 0;
165 }

References CompressFileHandle::private_data.

Referenced by InitCompressFileHandleNone().

◆ get_error_none()

static const char* get_error_none ( CompressFileHandle CFH)
static

Definition at line 118 of file compress_none.c.

119 {
120  return strerror(errno);
121 }
#define strerror
Definition: port.h:251

References strerror.

Referenced by InitCompressFileHandleNone().

◆ getc_none()

static int getc_none ( CompressFileHandle CFH)
static

Definition at line 130 of file compress_none.c.

131 {
132  FILE *fp = (FILE *) CFH->private_data;
133  int ret;
134 
135  ret = fgetc(fp);
136  if (ret == EOF)
137  {
138  if (!feof(fp))
139  pg_fatal("could not read from input file: %m");
140  else
141  pg_fatal("could not read from input file: end of file");
142  }
143 
144  return ret;
145 }
#define pg_fatal(...)

References pg_fatal, and CompressFileHandle::private_data.

Referenced by InitCompressFileHandleNone().

◆ gets_none()

static char* gets_none ( char *  ptr,
int  size,
CompressFileHandle CFH 
)
static

Definition at line 124 of file compress_none.c.

125 {
126  return fgets(ptr, size, (FILE *) CFH->private_data);
127 }
static pg_noinline void Size size
Definition: slab.c:607

References CompressFileHandle::private_data, and size.

Referenced by InitCompressFileHandleNone().

◆ InitCompressFileHandleNone()

void InitCompressFileHandleNone ( CompressFileHandle CFH,
const pg_compress_specification  compression_spec 
)

Definition at line 200 of file compress_none.c.

202 {
203  CFH->open_func = open_none;
205  CFH->read_func = read_none;
206  CFH->write_func = write_none;
207  CFH->gets_func = gets_none;
208  CFH->getc_func = getc_none;
209  CFH->close_func = close_none;
210  CFH->eof_func = eof_none;
212 
213  CFH->private_data = NULL;
214 }
static bool close_none(CompressFileHandle *CFH)
static int getc_none(CompressFileHandle *CFH)
static bool write_none(const void *ptr, size_t size, CompressFileHandle *CFH)
static bool eof_none(CompressFileHandle *CFH)
static char * gets_none(char *ptr, int size, CompressFileHandle *CFH)
static bool open_write_none(const char *path, const char *mode, CompressFileHandle *CFH)
static const char * get_error_none(CompressFileHandle *CFH)
static bool read_none(void *ptr, size_t size, size_t *rsize, CompressFileHandle *CFH)
Definition: compress_none.c:87
static bool open_none(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
bool(* open_write_func)(const char *path, const char *mode, CompressFileHandle *CFH)
Definition: compress_io.h:122
const char *(* get_error_func)(CompressFileHandle *CFH)
Definition: compress_io.h:181
bool(* write_func)(const void *ptr, size_t size, struct CompressFileHandle *CFH)
Definition: compress_io.h:139
int(* getc_func)(CompressFileHandle *CFH)
Definition: compress_io.h:161
char *(* gets_func)(char *s, int size, CompressFileHandle *CFH)
Definition: compress_io.h:152
bool(* eof_func)(CompressFileHandle *CFH)
Definition: compress_io.h:168
bool(* open_func)(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
Definition: compress_io.h:111
bool(* close_func)(CompressFileHandle *CFH)
Definition: compress_io.h:175
bool(* read_func)(void *ptr, size_t size, size_t *rsize, CompressFileHandle *CFH)
Definition: compress_io.h:131

References CompressFileHandle::close_func, close_none(), CompressFileHandle::eof_func, eof_none(), CompressFileHandle::get_error_func, get_error_none(), CompressFileHandle::getc_func, getc_none(), CompressFileHandle::gets_func, gets_none(), CompressFileHandle::open_func, open_none(), CompressFileHandle::open_write_func, open_write_none(), CompressFileHandle::private_data, CompressFileHandle::read_func, read_none(), CompressFileHandle::write_func, and write_none().

Referenced by InitCompressFileHandle().

◆ InitCompressorNone()

void InitCompressorNone ( CompressorState cs,
const pg_compress_specification  compression_spec 
)

Definition at line 66 of file compress_none.c.

68 {
71  cs->end = EndCompressorNone;
72 
73  cs->compression_spec = compression_spec;
74 }
static void EndCompressorNone(ArchiveHandle *AH, CompressorState *cs)
Definition: compress_none.c:56
static void WriteDataToArchiveNone(ArchiveHandle *AH, CompressorState *cs, const void *data, size_t dLen)
Definition: compress_none.c:49
static void ReadDataFromArchiveNone(ArchiveHandle *AH, CompressorState *cs)
Definition: compress_none.c:30
void(* readData)(ArchiveHandle *AH, CompressorState *cs)
Definition: compress_io.h:56
pg_compress_specification compression_spec
Definition: compress_io.h:82
void(* end)(ArchiveHandle *AH, CompressorState *cs)
Definition: compress_io.h:67
void(* writeData)(ArchiveHandle *AH, CompressorState *cs, const void *data, size_t dLen)
Definition: compress_io.h:61

References CompressorState::compression_spec, CompressorState::end, EndCompressorNone(), CompressorState::readData, ReadDataFromArchiveNone(), CompressorState::writeData, and WriteDataToArchiveNone().

Referenced by AllocateCompressor().

◆ open_none()

static bool open_none ( const char *  path,
int  fd,
const char *  mode,
CompressFileHandle CFH 
)
static

Definition at line 168 of file compress_none.c.

169 {
170  Assert(CFH->private_data == NULL);
171 
172  if (fd >= 0)
173  CFH->private_data = fdopen(dup(fd), mode);
174  else
175  CFH->private_data = fopen(path, mode);
176 
177  if (CFH->private_data == NULL)
178  return false;
179 
180  return true;
181 }
#define Assert(condition)
Definition: c.h:812
static PgChecksumMode mode
Definition: pg_checksums.c:55
static int fd(const char *x, int i)
Definition: preproc-init.c:105

References Assert, fd(), mode, and CompressFileHandle::private_data.

Referenced by InitCompressFileHandleNone().

◆ open_write_none()

static bool open_write_none ( const char *  path,
const char *  mode,
CompressFileHandle CFH 
)
static

Definition at line 184 of file compress_none.c.

185 {
186  Assert(CFH->private_data == NULL);
187 
188  CFH->private_data = fopen(path, mode);
189  if (CFH->private_data == NULL)
190  return false;
191 
192  return true;
193 }

References Assert, mode, and CompressFileHandle::private_data.

Referenced by InitCompressFileHandleNone().

◆ read_none()

static bool read_none ( void *  ptr,
size_t  size,
size_t *  rsize,
CompressFileHandle CFH 
)
static

Definition at line 87 of file compress_none.c.

88 {
89  FILE *fp = (FILE *) CFH->private_data;
90  size_t ret;
91 
92  if (size == 0)
93  return true;
94 
95  ret = fread(ptr, 1, size, fp);
96  if (ret != size && !feof(fp))
97  pg_fatal("could not read from input file: %m");
98 
99  if (rsize)
100  *rsize = ret;
101 
102  return true;
103 }

References if(), pg_fatal, CompressFileHandle::private_data, and size.

Referenced by InitCompressFileHandleNone().

◆ ReadDataFromArchiveNone()

static void ReadDataFromArchiveNone ( ArchiveHandle AH,
CompressorState cs 
)
static

Definition at line 30 of file compress_none.c.

31 {
32  size_t cnt;
33  char *buf;
34  size_t buflen;
35 
36  buflen = DEFAULT_IO_BUFFER_SIZE;
37  buf = pg_malloc(buflen);
38 
39  while ((cnt = cs->readF(AH, &buf, &buflen)))
40  {
41  ahwrite(buf, 1, cnt, AH);
42  }
43 
44  free(buf);
45 }
#define DEFAULT_IO_BUFFER_SIZE
Definition: compress_io.h:27
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define free(a)
Definition: header.h:65
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
static char * buf
Definition: pg_test_fsync.c:72
ReadFunc readF
Definition: compress_io.h:72

References ahwrite(), buf, DEFAULT_IO_BUFFER_SIZE, free, pg_malloc(), and CompressorState::readF.

Referenced by InitCompressorNone().

◆ write_none()

static bool write_none ( const void *  ptr,
size_t  size,
CompressFileHandle CFH 
)
static

Definition at line 106 of file compress_none.c.

107 {
108  size_t ret;
109 
110  ret = fwrite(ptr, 1, size, (FILE *) CFH->private_data);
111  if (ret != size)
112  return false;
113 
114  return true;
115 }

References CompressFileHandle::private_data, and size.

Referenced by InitCompressFileHandleNone().

◆ WriteDataToArchiveNone()

static void WriteDataToArchiveNone ( ArchiveHandle AH,
CompressorState cs,
const void *  data,
size_t  dLen 
)
static

Definition at line 49 of file compress_none.c.

51 {
52  cs->writeF(AH, data, dLen);
53 }
const void * data
WriteFunc writeF
Definition: compress_io.h:77

References data, and CompressorState::writeF.

Referenced by InitCompressorNone().