Beispiel #1
0
int xdlt_load_mmfile(char const *fname, mmfile_t *mf, int binmode) {
	char cc;
	int fd;
	long size;
	char *blk;

	if (xdl_init_mmfile(mf, XDLT_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) {

		return -1;
	}
	if ((fd = open(fname, O_RDONLY)) == -1) {
		perror(fname);
		xdl_free_mmfile(mf);
		return -1;
	}
	size = lseek(fd, 0, SEEK_END);
	lseek(fd, 0, SEEK_SET);
	if (!(blk = (char *) xdl_mmfile_writeallocate(mf, size))) {
		xdl_free_mmfile(mf);
		close(fd);
		return -1;
	}
	if (read(fd, blk, (size_t) size) != (size_t) size) {
		perror(fname);
		xdl_free_mmfile(mf);
		close(fd);
		return -1;
	}
	close(fd);

	return 0;
}
Beispiel #2
0
long xdl_writem_mmfile(mmfile_t *mmf, mmbuffer_t *mb, int nbuf) {
	int i;
	long size;
	char *data;

	for (i = 0, size = 0; i < nbuf; i++)
		size += mb[i].size;
	if (!(data = (char *) xdl_mmfile_writeallocate(mmf, size)))
		return -1;
	for (i = 0; i < nbuf; i++) {
		memcpy(data, mb[i].ptr, mb[i].size);
		data += mb[i].size;
	}

	return size;
}
Beispiel #3
0
int xdlt_create_file(mmfile_t *mf, long size) {
	long lnsize, csize;
	char *data;

	if (xdl_init_mmfile(mf, XDLT_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) {

		return -1;
	}
	if (!(data = xdl_mmfile_writeallocate(mf, size))) {

		xdl_free_mmfile(mf);
		return -1;
	}
	for (csize = 0; size - csize > XDLT_MAX_LINE_SIZE;) {
		lnsize = xdlt_gen_line(data, XDLT_MAX_LINE_SIZE);
		data += lnsize;
		csize += lnsize;
	}
	if (csize < size)
		xdlt_gen_line(data, -(size - csize));

	return 0;
}
Beispiel #4
0
int xdl_mmfile_compact(mmfile_t *mmfo, mmfile_t *mmfc, long bsize, unsigned long flags) {
	long fsize = xdl_mmfile_size(mmfo), size;
	char *data;
	char const *blk;

	if (xdl_init_mmfile(mmfc, bsize, flags) < 0) {

		return -1;
	}
	if (!(data = (char *) xdl_mmfile_writeallocate(mmfc, fsize))) {

		xdl_free_mmfile(mmfc);
		return -1;
	}
	if ((blk = (char const *) xdl_mmfile_first(mmfo, &size)) != NULL) {
		do {
			memcpy(data, blk, size);
			data += size;
		} while ((blk = (char const *) xdl_mmfile_next(mmfo, &size)) != NULL);
	}

	return 0;
}