File: offst_source.c

package info (click to toggle)
libburn 1.5.6-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,244 kB
  • sloc: ansic: 38,038; sh: 11,577; makefile: 182
file content (134 lines) | stat: -rw-r--r-- 2,607 bytes parent folder | download | duplicates (8)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

/*
  cc -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS -g -o test/offst_source test/offst_source.c -lburn
*/

#include "../libburn/libburn.h" 

/* Just everything from test/libburner.c */
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>


static int create_original(struct burn_source **original, char *path, int flag)
{
	printf("create_original: path='%s'\n", path);
	*original = burn_file_source_new(path, NULL);
	if (*original == NULL)
		return 0;
	return 1;
}


static int set_up_offst_sources(struct burn_source *original,
				struct burn_source *offsetters[],
				int count, int flag)
{
	int i;
	off_t start = 3, size = 10, gap = 7;

	for (i = 0; i < count; i++) {
		offsetters[i] = burn_offst_source_new(original,
					i > 0 ? offsetters[i - 1] : NULL,
					start, size, 0);
		if (offsetters[i] == NULL)
			return 0;
		printf("set_up_offst_sources: idx=%d, start=%d\n",
			 i, (int) start);
		start += size + gap;
	}
	return 1;
}


static int consume_source(struct burn_source *src, int flag)
{
	int ret, count = 0;
	unsigned char buf[1];

	while (1) {
		ret = src->read_xt(src, buf, 1);
		if (ret < 0) {
			printf("\n");
			fprintf(stderr, "consume_source: count=%d, ret=%d\n",
					count, ret);
			return 0;
		}
		if (ret == 0)
	break;
		printf("%u ", buf[0]);
		count++;
	}
	printf(" count=%d\n", count);
	return 1;
}


static int consume_all_sources(struct burn_source *offsetters[],
                                int count, int flag)
{
	int i, ret;

	for (i = 0; i < count; i++) {
		printf("consume_source: idx=%d\n", i);
		ret = consume_source(offsetters[i], 0);
		if (ret <= 0)
			return ret;
	}
	return 1;
}


static int free_all_sources(struct burn_source *original,
                                struct burn_source *offsetters[],
                                int count, int flag)
{
	int i;

	for (i = 0; i < count; i++)
		burn_source_free(offsetters[i]);
	burn_source_free(original);
	return 1;
}


int main(int argc, char **argv)
{
	int ret;
	char *path = "./COPYRIGHT";
	struct burn_source *original = NULL, *offsetters[4];

	if (argc > 1)
		path = argv[1];

	if (burn_initialize() == 0)
		exit(1);

	ret = create_original(&original, path, 0);
	if (ret <= 0)
		exit(2);

	ret = set_up_offst_sources(original, offsetters, 4, 0);
	if (ret <= 0)
		exit(3);

	ret = consume_all_sources(offsetters, 4, 0);
	if (ret <= 0)
		exit(4);

	ret = free_all_sources(original, offsetters, 4, 0);
	if (ret <= 0)
		exit(5);

	burn_finish();
	exit(0);
}