<commit_before>#include <iostream>

#include <cstring>
#include <csignal>

#include <unistd.h>

#include "gestionFichiersw.hpp"
#include "pipe.hpp"

constexpr size_t const TAILLEBUF = 255;

int main() {
	try {
		Pipe myPipe(/* nonBlocking = */ true);
		pid_t pid = fork();

		if(pid == -1) {
			std::perror("fork() a échoué");
			exit(errno);
		} else if(pid == 0) {
			char status[TAILLEBUF];

			sleep(10);

			myPipe >> status;

			if(std::strcmp(status, "Finished\n")) {
				std::cout << "Too late: safe closed." << std::endl;
				myPipe << "Too late\n";
				return EPERM;
			}

		} else {
			try {
				char code[TAILLEBUF];
				std::cout << "You have 10 seconds to open the safe." << std::endl
				          << "Please enter the code of the safe: " << std::flush;

				IFile consoleIn(0, TAILLEBUF);
				consoleIn >> code;

				char status[TAILLEBUF];
				myPipe >> status;
				myPipe << "Finished\n";

				bool invalidCode = std::strcmp(code, "1234\n"),
				     notTooLate = std::strcmp(status, "Too late\n");
				if(notTooLate) {
					if(invalidCode) {
						std::cout << "Code incorrect: safe closed" << std::endl;
					} else {
						std::cout << "Code correct: safe opened." << std::endl;
					}
				}

			} catch(std::ios_base::failure const& e) {
				std::cerr << "Error: " << e.what() << std::endl;
				return e.code().value();
			}
		}

	} catch(std::system_error const& e) {
		std::cerr << "Error: " << e.what() << std::endl;
		return e.code().value();
	}
}<commit_msg>Using signals instead of pipes for TD3-exIII<commit_after>#include <iostream>

#include <cstring>
#include <csignal>

#include <unistd.h>

#include "gestionFichiersw.hpp"
#include "pipe.hpp"

constexpr size_t const TAILLEBUF = 255;

int main() {
	try {
		pid_t pid = fork();

		if(pid == -1) {
			std::perror("fork() a échoué");
			exit(errno);
		} else if(pid == 0) {
			sleep(10);
			kill(getppid(), SIGUSR1);
			return EPERM;
		} else {
			try {
				char code[TAILLEBUF];
				std::cout << "You have 10 seconds to open the safe." << std::endl
				          << "Please enter the code of the safe: " << std::flush;

				//bool notTooLate = true;

				// Cannot pass a lambda with a capture to signal (cannot be converted to a function
				// pointer)
				signal(SIGUSR1, [/*&notTooLate*/](int sig) {
					if(sig == SIGUSR1) {
						std::cout << "\nToo late: safe closed" << std::endl;
						// notTooLate = false;
						wait();
						exit(EPERM);
					}
				});

				IFile consoleIn(0, TAILLEBUF);
				consoleIn >> code;

				bool invalidCode = std::strcmp(code, "1234\n");

				if(invalidCode) {
					std::cout << "Code incorrect: safe closed" << std::endl;
				} else {
					std::cout << "Code correct: safe opened." << std::endl;
				}

				signal(SIGUSR1, SIG_IGN);
				// Stop the child
				kill(pid, SIGTERM);

				return invalidCode ? EPERM : 0;

			} catch(std::ios_base::failure const& e) {
				std::cerr << "Error: " << e.what() << std::endl;
				return e.code().value();
			}
		}

	} catch(std::system_error const& e) {
		std::cerr << "Error: " << e.what() << std::endl;
		return e.code().value();
	}
}
{'fraction_non_alphanumeric': 0.17914783731439637, 'fraction_numerical': 0.010974822466107165, 'mean_word_length': 2.859277708592777, 'pattern_counts': {'":': 0, '<': 79, '<?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': '5725836', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1128, 'n_words': 281}