void VerilatedVcd::bufferFlush () {
    // We add output data to m_writep.
    // When it gets nearly full we dump it using this routine which calls write()
    // This is much faster than using buffered I/O
    if (VL_UNLIKELY(!isOpen())) return;
    char* wp = m_wrBufp;
    while (1) {
	ssize_t remaining = (m_writep - wp);
	if (remaining==0) break;
	errno = 0;
	ssize_t got = write (m_fd, wp, remaining);
	if (got>0) {
	    wp += got;
	    m_wroteBytes += got;
	} else if (got < 0) {
	    if (errno != EAGAIN && errno != EINTR) {
		// write failed, presume error (perhaps out of disk space)
		string msg = (string)"VerilatedVcd::bufferFlush: "+strerror(errno);
		vl_fatal("",0,"",msg.c_str());
		closeErr();
		break;
	    }
	}
    }

    // Reset buffer
    m_writep = m_wrBufp;
}
Esempio n. 2
0
File: rw.c Progetto: taysom/tau
/* Normal read/lseek tests */
static void rdseek (void)
{
	/* SEEK_DATA and SEEK_HOLE were added in 3.1 */
	enum { SEEK_INVALID = 99999 };	/* Invalid value for whence for seek */
	u8 buf[Local_option.block_size];
	int fd;
	s64 offset;
	u64 size;

	/* Read BigFile and verify contents */
	fd = open(BigFile, O_RDWR, 0);
	size = Local_option.size_big_file;
	for (offset = 0; size; offset += Local_option.block_size) {
		unint n = Local_option.block_size;
		if (n > size) n = size;
		read(fd, buf, n);
		CheckFill(buf, n, offset);
		size -= n;
	}

	/* Try reading passed eof */
	readCheckSize(fd, buf, sizeof(buf), 0);

	/* Start read before eof but go beyond eof */
	offset = Local_option.size_big_file - 47;
	lseek(fd, offset, SEEK_SET);
	readCheckSize(fd, buf, Local_option.block_size, 47);
	CheckFill(buf, 47, offset);

	/* Seek to middle of file and verify contents */
	offset = Local_option.size_big_file / 2;
	lseek(fd, offset, SEEK_SET);
	read(fd, buf, Local_option.block_size);
	CheckFill(buf, Local_option.block_size, offset);

	/* Seek from current position forward 2 blocks */
	offset += 3 * Local_option.block_size;
	lseekCheckOffset(fd, 2 * Local_option.block_size, SEEK_CUR, offset);
	read(fd, buf, Local_option.block_size);
	CheckFill(buf, Local_option.block_size, offset);

	/* Seek from eof back 3 blocks */
	offset = Local_option.size_big_file - 3 * Local_option.block_size;
	lseekCheckOffset(fd, -(3 * Local_option.block_size), SEEK_END, offset);
	read(fd, buf, Local_option.block_size);
	CheckFill(buf, Local_option.block_size, offset);

	/* Seek beyond eof */
	offset = Local_option.size_big_file + Local_option.block_size;
	lseek(fd, offset, SEEK_SET);
	readCheckSize(fd, buf, Local_option.block_size, 0);

	/* Seek bad whence */
	lseekErr(EINVAL, fd, 0, SEEK_INVALID);

	/* Seek negative offset */
	lseekErr(EINVAL, fd, -3, SEEK_SET);

	close(fd);

	/* Seek on closed fd */
	lseekErr(EBADF, fd, 0, SEEK_SET);

	/* 2nd close is an error */
	closeErr(EBADF, fd);
}