コード例 #1
0
ファイル: xdffile.c プロジェクト: serafperd/xdffileio
/* \param xdf		pointer to a valid xdf file
 *
 * API FUNCTION
 * Closes the xDF file and free the resources allocated
 */
API_EXPORTED int xdf_close(struct xdf* xdf)
{
	int retval = 0;
	struct xdfch *ch, *prev;

	if (!xdf)
		return xdf_set_error(EINVAL);

	if (xdf->ready) {
		if ((xdf->mode == XDF_WRITE) && finish_record(xdf))
			retval = -1;
		
		finish_transfer_thread(xdf);
		free_transfer_objects(xdf);

		if ((xdf->mode == XDF_WRITE) && complete_file_content(xdf))
			retval = -1;
	}

	if ((xdf->fd >= 0) && close(xdf->fd))
		retval = -1;

	// Free channels and file
	free(xdf->array_stride);
	destroy_event_table(xdf->table);
	ch=xdf->channels;
	while (ch) {
		prev = ch;
		ch = ch->next;
		free((char*)prev - xdf->ops->choff);
	}
	free((char*)xdf - xdf->ops->fileoff);

	return retval;
}
コード例 #2
0
ファイル: archive-tar.c プロジェクト: Kaybug0112/git
/*
 * queues up writes, so that all our write(2) calls write exactly one
 * full block; pads writes to RECORDSIZE
 */
static int stream_blocked(const unsigned char *sha1)
{
	struct git_istream *st;
	enum object_type type;
	unsigned long sz;
	char buf[BLOCKSIZE];
	ssize_t readlen;

	st = open_istream(sha1, &type, &sz, NULL);
	if (!st)
		return error("cannot stream blob %s", sha1_to_hex(sha1));
	for (;;) {
		readlen = read_istream(st, buf, sizeof(buf));
		if (readlen <= 0)
			break;
		do_write_blocked(buf, readlen);
	}
	close_istream(st);
	if (!readlen)
		finish_record();
	return readlen;
}
コード例 #3
0
ファイル: archive-tar.c プロジェクト: Kaybug0112/git
static void write_blocked(const void *data, unsigned long size)
{
	do_write_blocked(data, size);
	finish_record();
}