File: buffer.h

package info (click to toggle)
s390-tools 2.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,288 kB
  • sloc: ansic: 187,079; sh: 12,157; cpp: 5,049; makefile: 2,812; perl: 2,541; asm: 1,097; python: 697; xml: 29
file content (50 lines) | stat: -rw-r--r-- 1,726 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * dump2tar - tool to dump files and command output into a tar archive
 *
 * Data buffering functions
 *
 * Copyright IBM Corp. 2016, 2017
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#ifndef BUFFER_H
#define BUFFER_H

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

/* Buffers for building tar file entries */
struct buffer {
	size_t total;	/* Total number of bytes in buffer */
	size_t off;	/* Current offset to next free byte in memory buffer */
	size_t size;	/* Memory buffer size */
	char *addr;	/* Memory buffer address */
	bool fd_open;	/* Has fd been openend yet? */
	FILE *file;	/* FILE * of file containing previous buffer data */
	int fd;		/* Handle of file containing previous buffer data */
};

void buffer_init(struct buffer *buffer, size_t size);
struct buffer *buffer_alloc(size_t size);
void buffer_reset(struct buffer *buffer);
void buffer_close(struct buffer *buffer);
void buffer_free(struct buffer *buffer, bool dyn);
int buffer_open(struct buffer *buffer);
int buffer_flush(struct buffer *buffer);
ssize_t buffer_make_room(struct buffer *buffer, size_t size, bool usefile,
			 size_t max_buffer_size);
int buffer_truncate(struct buffer *buffer, size_t len);

ssize_t buffer_read_fd(struct buffer *buffer, int fd, size_t chunk,
		       bool usefile, size_t max_buffer_size);
int buffer_add_data(struct buffer *buffer, char *addr, size_t len,
		    bool usefile, size_t max_buffer_size);

typedef int (*buffer_cb_t)(void *data, void *addr, size_t len);
int buffer_iterate(struct buffer *buffer, buffer_cb_t cb, void *data);
void buffer_print(struct buffer *buffer);

#endif /* BUFFER_H */