Alien-Libjio

 view release on metacpan or  search on metacpan

libjio/libjio/unix.c  view on Meta::CPAN


	rv = jtrans_add_w(ts, buf, count, offset);
	if (rv < 0)
		goto exit;

	rv = jtrans_commit(ts);

exit:
	jtrans_free(ts);

	return (rv >= 0) ? count : rv;
}

/* writev() wrapper */
ssize_t jwritev(struct jfs *fs, const struct iovec *vector, int count)
{
	int i;
	size_t sum;
	ssize_t rv;
	off_t ipos, t;
	struct jtrans *ts;

	ts = jtrans_new(fs, 0);
	if (ts == NULL)
		return -1;

	pthread_mutex_lock(&(fs->lock));

	if (fs->open_flags & O_APPEND)
		ipos = lseek(fs->fd, 0, SEEK_END);
	else
		ipos = lseek(fs->fd, 0, SEEK_CUR);

	t = ipos;

	sum = 0;
	for (i = 0; i < count; i++) {
		rv = jtrans_add_w(ts, vector[i].iov_base,
				vector[i].iov_len, t);
		if (rv < 0)
			goto exit;

		sum += vector[i].iov_len;
		t += vector[i].iov_len;
	}

	rv = jtrans_commit(ts);

	if (rv >= 0)
		lseek(fs->fd, sum, SEEK_CUR);

exit:
	pthread_mutex_unlock(&(fs->lock));

	jtrans_free(ts);

	return (rv >= 0) ? sum : rv;
}

/* Truncate a file. Be careful with this */
int jtruncate(struct jfs *fs, off_t length)
{
	int rv;

	/* lock from length to the end of file */
	plockf(fs->fd, F_LOCKW, length, 0);
	rv = ftruncate(fs->fd, length);
	plockf(fs->fd, F_UNLOCK, length, 0);

	return rv;
}

/* lseek() wrapper */
off_t jlseek(struct jfs *fs, off_t offset, int whence)
{
	off_t rv;

	pthread_mutex_lock(&(fs->lock));
	rv = lseek(fs->fd, offset, whence);
	pthread_mutex_unlock(&(fs->lock));

	return rv;
}



( run in 1.100 second using v1.01-cache-2.11-cpan-d59ab9ce9b0 )