35 #define Z_CHUNK_SZ 1024*128 36 #define Z_MODE_STR "wb1" 42 syslog(LOG_ERR,
"Internal pointer error in 'stream_init'");
49 if (p_dst_fname ==
NULL)
60 syslog(LOG_ERR,
"Cannot open output filename <%s>. %s", p_dst_fname, strerror(errno));
67 syslog(LOG_WARNING,
"The coredump will be processed, but not written");
70 if (p_src_fname ==
NULL)
76 if ((p_fs->
stream = fopen(p_src_fname,
"rb")) ==
NULL)
78 syslog(LOG_ERR,
"Cannot open filename <%s>. %s", p_src_fname, strerror(errno));
86 syslog(LOG_ERR,
"Cannot allocate %d bytes for read buffer. %s",
Z_CHUNK_SZ, strerror(errno));
97 syslog(LOG_ERR,
"Internal pointer error in 'stream_close'");
125 unsigned int byte_read = 0;
129 syslog(LOG_ERR,
"Internal pointer error in 'stream_read'");
135 syslog(LOG_ERR,
"Internal buffer pointer error in 'stream_read'");
139 if ((byte_read = fread(p_buf, 1, p_size, p_fs->
stream)) != p_size)
141 syslog(LOG_WARNING,
"Cannot read %d bytes from src. %s", p_size, strerror(errno));
145 p_fs->
offset += byte_read;
157 syslog(LOG_ERR,
"Internal pointer error in 'stream_move_ahead'");
161 while (!feof(p_fs->
stream))
168 p_fs->
offset += read_bytes;
171 syslog(LOG_WARNING,
"Error reading from the src stream: %s", strerror(errno));
181 int bytes_to_read = 0;
185 syslog(LOG_ERR,
"Internal pointer error in 'stream_move_to_offest'");
189 bytes_to_read = p_offset - p_fs->
offset;
196 int bytes_to_read = p_nbbytes;
200 syslog(LOG_ERR,
"Internal pointer error in 'stream_move_ahead'");
204 while (bytes_to_read > 0)
207 size_t read_bytes = fread(p_fs->
read_buf, 1, chunk_size, p_fs->
stream);
209 if (read_bytes != chunk_size)
211 syslog(LOG_WARNING,
"Cannot move ahead by %d bytes from src. Read %lu bytes", p_nbbytes, read_bytes);
218 bytes_to_read -= chunk_size;
221 p_fs->
offset += p_nbbytes;
230 syslog(LOG_ERR,
"Internal pointer error in 'stream_get_offset'");
int stream_finish(file_streamer_t *p_fs)
unsigned int stream_get_offset(file_streamer_t *p_fs)
int stream_move_to_offest(file_streamer_t *p_fs, unsigned int p_offset)
cdh_status_t stream_read(file_streamer_t *p_fs, void *p_buf, unsigned int p_size)
cdh_status_t stream_close(file_streamer_t *p_fs)
cdh_status_t stream_init(file_streamer_t *p_fs, const char *p_src_fname, const char *p_dst_fname)
int stream_move_ahead(file_streamer_t *p_fs, unsigned int p_nbbytes)