<commit_before>/*
 * 06/06/2017: trunc-test.c
 */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int
main(int argc, char **argv)
{
	long size;
	int i, fd, ret;
	struct stat stbuf;
	char *buf, *filename;

	if (argc != 3) {
		printf("Usage: a.out filename size\n");
		exit (0);
	}

	filename = argv[1];
	size = atol(argv[2]);
	if (size < 4096) {
		printf("The size of the file is too small!\n");
		exit (0);
	}

	srandom(1234);
	buf = malloc(size);

	for (i = 0; i < size; i++)
		buf[i] = random();

	fd = open(filename, O_RDWR|O_TRUNC|O_EXCL|O_CREAT, 0600);
	if (fd < 0) {
		printf("Open fails with errno = %d\n", errno);
		exit (0);
	}
	ret = ftruncate(fd, size);
	if (ret < 0) {
		printf("Truncate fails with errno = %d\n", errno);
		exit (0);
	}
	ret = lseek(fd, size - 1234, SEEK_SET);
	if (ret < 0) {
		printf("Seek fails with errno = %d\n", errno);
		exit (0);
	}

	ret = write(fd, buf, 4096);
	if (ret != 4096) {
		printf("Write fails with errno = %d\n", errno);
		exit (0);
	}

	ret = stat(filename, &stbuf);
	if (ret < 0) {
		printf("Stat fails with errno = %d\n", errno);
		exit (0);
	}
	if (stbuf.st_size != size - 1234 + 4096) {
		printf("Unexpected file size = %ld\n", stbuf.st_size);
		exit (0);
	}

	ret = ftruncate(fd, 1024);
	if (ret < 0) {
		printf("Truncate fails with errno = %d\n", errno);
		exit (0);
	}
	ret = lseek(fd, 0, SEEK_SET);
	if (ret < 0) {
		printf("Seek fails with errno = %d\n", errno);
		exit (0);
	}

	ret = read(fd, buf, 10240);
	if (ret < 0) {
		printf("Read fails with errno = %d\n", errno);
		exit (0);
	}
	if (ret != 1024) {
		printf("Unexpected bytes returned = %d\n", ret);
		exit (0);
	}
	for (i = 0; i < ret; i++) {
		if (buf[i]) {
			printf("Unexpected file size detected.\n");
			exit (0);
		}
	}
	printf("All tests has passed successfully.\n");
	close(fd);
}<commit_msg>make the test more interesting<commit_after>/*
 * 06/06/2017: trunc-test.c
 */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int
main(int argc, char **argv)
{
	long size;
	int i, fd, ret;
	struct stat stbuf;
	char *buf, *filename;

	if (argc != 3) {
		printf("Usage: a.out filename size\n");
		exit (0);
	}

	filename = argv[1];
	size = atol(argv[2]);
	if (size < 4096) {
		printf("The size of the file is too small!\n");
		exit (0);
	}

	srandom(1234);
	buf = malloc(size);

	for (i = 0; i < size; i++)
		buf[i] = random();

	fd = open(filename, O_RDWR|O_TRUNC|O_EXCL|O_CREAT, 0600);
	if (fd < 0) {
		printf("Open fails with errno = %d\n", errno);
		exit (0);
	}
	ret = ftruncate(fd, size);
	if (ret < 0) {
		printf("Truncate fails with errno = %d\n", errno);
		exit (0);
	}
	ret = lseek(fd, size - 1234, SEEK_SET);
	if (ret < 0) {
		printf("Seek fails with errno = %d\n", errno);
		exit (0);
	}

	ret = write(fd, buf, 4096);
	if (ret != 4096) {
		printf("Write fails with errno = %d\n", errno);
		exit (0);
	}

	ret = stat(filename, &stbuf);
	if (ret < 0) {
		printf("Stat fails with errno = %d\n", errno);
		exit (0);
	}
	if (stbuf.st_size != size - 1234 + 4096) {
		printf("Unexpected file size = %ld\n", stbuf.st_size);
		exit (0);
	}

	ret = ftruncate(fd, 1024);
	if (ret < 0) {
		printf("Truncate fails with errno = %d\n", errno);
		exit (0);
	}
	ret = lseek(fd, 0, SEEK_SET);
	if (ret < 0) {
		printf("Seek fails with errno = %d\n", errno);
		exit (0);
	}

	ret = read(fd, buf, 10240);
	if (ret < 0) {
		printf("Read fails with errno = %d\n", errno);
		exit (0);
	}
	if (ret != 1024) {
		printf("Unexpected bytes returned = %d\n", ret);
		exit (0);
	}
	for (i = 0; i < ret; i++) {
		if (buf[i]) {
			printf("Unexpected file size detected.\n");
			exit (0);
		}
	}

	ret = ftruncate(fd, 1000);
	if (ret < 0) {
		printf("Truncate fails with errno = %d\n", errno);
		exit (0);
	}
	ret = stat(filename, &stbuf);
	if (ret < 0) {
		printf("Stat fails with errno = %d\n", errno);
		exit (0);
	}
	if (stbuf.st_size != 1000) {
		printf("Unexpected file size = %ld\n", stbuf.st_size);
		exit (0);
	}

	ret = ftruncate(fd, 234);
	if (ret < 0) {
		printf("Truncate fails with errno = %d\n", errno);
		exit (0);
	}
	ret = stat(filename, &stbuf);
	if (ret < 0) {
		printf("Stat fails with errno = %d\n", errno);
		exit (0);
	}
	if (stbuf.st_size != 234) {
		printf("Unexpected file size = %ld\n", stbuf.st_size);
		exit (0);
	}

	ret = ftruncate(fd, 23400);
	if (ret < 0) {
		printf("Truncate fails with errno = %d\n", errno);
		exit (0);
	}
	ret = stat(filename, &stbuf);
	if (ret < 0) {
		printf("Stat fails with errno = %d\n", errno);
		exit (0);
	}
	if (stbuf.st_size != 23400) {
		printf("Unexpected file size = %ld\n", stbuf.st_size);
		exit (0);
	}

	printf("All tests has passed successfully.\n");
	close(fd);
}
{'fraction_non_alphanumeric': 0.20004145936981757, 'fraction_numerical': 0.04083747927031509, 'mean_word_length': 3.1883680555555554, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '307284', 'n_tokens_mistral': 2341, 'n_tokens_neox': 2042, 'n_words': 580}