<commit_before>/**
 * @file
 *
 * @date Nov 29, 2013
 * @author: <NAME>
 */
#include <errno.h>
#include <fcntl.h>

#include <kernel/task.h>

#include <kernel/task/resource/idesc_table.h>
#include <kernel/task/resource/idesc.h>

#include <kernel/task/resource/index_descriptor.h>

static inline struct idesc_table *task_self_idesc_table(void) {
	struct idesc_table *it;

	it = task_resource_idesc_table(task_self());
	assert(it);

	return it;
}

int index_descriptor_add(struct idesc *idesc) {

	return idesc_table_add(task_self_idesc_table(), idesc, 0);
}

struct idesc *index_descriptor_get(int idx) {

	return idesc_table_get(task_self_idesc_table(), idx);
}

int index_descritor_cloexec_get(int fd) {
	struct idesc_table *it;
	int fd_flags = 0;

	it = task_self_idesc_table();
	assert(it);

	if (idesc_is_cloexeced(it->idesc_table[fd])) {
		fd_flags |= FD_CLOEXEC;
	}
	return fd_flags;
}

int index_descriptor_cloexec_set(int fd, int cloexec) {
	struct idesc_table *it;

	it = task_resource_idesc_table(task_self());
	assert(it);

	if (cloexec | FD_CLOEXEC) {
		idesc_cloexec_set(it->idesc_table[fd]);
	} else {
		idesc_cloexec_clear(it->idesc_table[fd]);
	}
	return 0;
}

int index_descriptor_flags_get(int fd) {
	struct idesc *idesc;

	idesc = index_descriptor_get(fd);
	if (!idesc) {
		return -ENOENT;
	}

	return idesc->idesc_flags & ~O_ACCESS_MASK;
}

int index_descriptor_flags_set(int fd, int flags) {
	struct idesc *idesc;

	idesc = index_descriptor_get(fd);
	if (!idesc) {
		return -ENOENT;
	}

	flags &= ~O_ACCESS_MASK;
	idesc->idesc_flags |= flags;

	return 0;
}<commit_msg>kernel: Fix CLOEXEC flag set for index descriptors<commit_after>/**
 * @file
 *
 * @date Nov 29, 2013
 * @author: <NAME>
 */
#include <errno.h>
#include <fcntl.h>

#include <kernel/task.h>

#include <kernel/task/resource/idesc_table.h>
#include <kernel/task/resource/idesc.h>

#include <kernel/task/resource/index_descriptor.h>

static inline struct idesc_table *task_self_idesc_table(void) {
	struct idesc_table *it;

	it = task_resource_idesc_table(task_self());
	assert(it);

	return it;
}

int index_descriptor_add(struct idesc *idesc) {

	return idesc_table_add(task_self_idesc_table(), idesc, 0);
}

struct idesc *index_descriptor_get(int idx) {

	return idesc_table_get(task_self_idesc_table(), idx);
}

int index_descritor_cloexec_get(int fd) {
	struct idesc_table *it;
	int fd_flags = 0;

	it = task_self_idesc_table();
	assert(it);

	if (idesc_is_cloexeced(it->idesc_table[fd])) {
		fd_flags |= FD_CLOEXEC;
	}
	return fd_flags;
}

int index_descriptor_cloexec_set(int fd, int cloexec) {
	struct idesc_table *it;

	it = task_resource_idesc_table(task_self());
	assert(it);

	if (cloexec & FD_CLOEXEC) {
		idesc_cloexec_set(it->idesc_table[fd]);
	} else {
		idesc_cloexec_clear(it->idesc_table[fd]);
	}
	return 0;
}

int index_descriptor_flags_get(int fd) {
	struct idesc *idesc;

	idesc = index_descriptor_get(fd);
	if (!idesc) {
		return -ENOENT;
	}

	return idesc->idesc_flags & ~O_ACCESS_MASK;
}

int index_descriptor_flags_set(int fd, int flags) {
	struct idesc *idesc;

	idesc = index_descriptor_get(fd);
	if (!idesc) {
		return -ENOENT;
	}

	flags &= ~O_ACCESS_MASK;
	idesc->idesc_flags |= flags;

	return 0;
}
{'fraction_non_alphanumeric': 0.13103018985371925, 'fraction_numerical': 0.006224712107065048, 'mean_word_length': 5.228682170542636, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, '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': '5204129', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1317, 'n_words': 247}