Пример #1
0
static int create_and_fill_file(const char *path, int number, size_t size,
	struct flow *fw)
{
	char full_fn[PATH_MAX];
	const char *filename;
	int fd, fine;
	void *buf;
	size_t remaining;
	uint64_t offset;
	ssize_t written;

	assert(size > 0);
	assert(size % fw->block_size == 0);

	/* Create the file. */
	
	full_fn_from_number(full_fn, &filename, path, number);
	printf("Creating file %s ... ", filename);
	fflush(stdout);
	fd = open(full_fn, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
	if (fd < 0) {
		if (errno == ENOSPC) {
			printf("No space left.\n");
			return 0;
		}
		err(errno, "Can't create file %s", full_fn);
	}
	assert(fd >= 0);

	/* Obtain the buffer. */
	buf = alloca(fw->block_size);
	assert(buf);

	/* Write content. */
	fine = 1;
	offset = (uint64_t)number * GIGABYTES;
	remaining = size;
	start_measurement(fw);
	while (remaining > 0) {
		offset = fill_buffer(buf, fw->block_size, offset);
		written = write(fd, buf, fw->block_size);
		if (written < 0) {
			if (errno == ENOSPC) {
				fine = 0;
				break;
			} else
				err(errno, "Write to file %s failed", full_fn);
		}
		assert(written == fw->block_size);
		remaining -= written;
		measure(fd, fw);
	}
	assert(!fine || remaining == 0);
	end_measurement(fd, fw);
	close(fd);
	
	printf("OK!\n");
	return fine;
}
Пример #2
0
int main() {
	int i = read_int();
	start_measurement();
	int res = fib(i);
	end_measurement();
	print_int(res);
	return 0;
}
Пример #3
0
void main() {	
	start_measurement();
	int res = fib(15);
	end_measurement();
	print_int(res);
}