<commit_before>#define _GNU_SOURCE
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include "__dirent.h"

DIR *opendir(const char *name)
{
	int fd;
	DIR *dir;

	if ((fd = open(name, O_RDONLY|O_DIRECTORY)) < 0)
		return 0;
	fcntl(fd, F_SETFD, FD_CLOEXEC);
	if (!(dir = calloc(1, sizeof *dir))) {
		close(fd);
		return 0;
	}
	dir->fd = fd;
	return dir;
}<commit_msg>avoid fd leak if opendir is cancelled when calloc has failed<commit_after>#define _GNU_SOURCE
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include "__dirent.h"
#include "syscall.h"

DIR *opendir(const char *name)
{
	int fd;
	DIR *dir;

	if ((fd = open(name, O_RDONLY|O_DIRECTORY)) < 0)
		return 0;
	fcntl(fd, F_SETFD, FD_CLOEXEC);
	if (!(dir = calloc(1, sizeof *dir))) {
		__syscall(SYS_close, fd);
		return 0;
	}
	dir->fd = fd;
	return dir;
}
{'fraction_non_alphanumeric': 0.17185929648241205, 'fraction_numerical': 0.008040201005025126, 'mean_word_length': 4.627118644067797, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '74175', 'n_tokens_mistral': 458, 'n_tokens_neox': 435, 'n_words': 109}