<commit_before>#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>

#include "zdtmtst.h"

const char *test_doc	= "Check that cwd didn't change";
const char *test_author	= "<NAME> <<EMAIL>>";

char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);

int main(int argc, char **argv)
{
	char cwd0[256], cwd1[256], cwd2[256];

	test_init(argc, argv);

	if (!getcwd(cwd0, sizeof(cwd0))) {
		err("can't get cwd: %m\n");
		exit(1);
	}

	if (mkdir(dirname, 0700)) {
		err("can't make directory %s: %m\n", dirname);
		exit(1);
	}

	if (chdir(dirname)) {
		err("can't change directory to %s: %m\n", dirname);
		goto cleanup;
	}

	if (!getcwd(cwd1, sizeof(cwd1))) {
		err("can't get cwd: %m\n");
		goto cleanup;
	}

	test_daemon();
	test_waitsig();

	if (!getcwd(cwd2, sizeof(cwd2))) {
		fail("can't get cwd: %m\n");
		goto cleanup;
	}

	if (strcmp(cwd1, cwd2))
		fail("%s != %s\n", cwd1, cwd2);
	else
		pass();
cleanup:
	chdir(cwd0);	/* return to the initial dir before writing out results */
	rmdir(dirname);
	return 0;
}<commit_msg>test/zdtm/cwd00: add error checking to cleanup code<commit_after>#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>

#include "zdtmtst.h"

const char *test_doc	= "Check that cwd didn't change";
const char *test_author	= "<NAME> <<EMAIL>>";

char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);

int main(int argc, char **argv)
{
	char cwd0[256], cwd1[256], cwd2[256];

	test_init(argc, argv);

	if (!getcwd(cwd0, sizeof(cwd0))) {
		err("can't get cwd: %m\n");
		exit(1);
	}

	if (mkdir(dirname, 0700)) {
		err("can't make directory %s: %m\n", dirname);
		exit(1);
	}

	if (chdir(dirname)) {
		err("can't change directory to %s: %m\n", dirname);
		goto cleanup;
	}

	if (!getcwd(cwd1, sizeof(cwd1))) {
		err("can't get cwd: %m\n");
		goto cleanup;
	}

	test_daemon();
	test_waitsig();

	if (!getcwd(cwd2, sizeof(cwd2))) {
		fail("can't get cwd: %m\n");
		goto cleanup;
	}

	if (strcmp(cwd1, cwd2))
		fail("%s != %s\n", cwd1, cwd2);
	else
		pass();
cleanup:
	/* return to the initial dir before writing out results */
	if (chdir(cwd0)) {
		err("can't change directory to %s: %m\n", cwd0);
		exit(1);
	}
	if (rmdir(dirname)) {
		err("can't remove directory %s: %m\n", dirname);
		exit(1);
	}
	return 0;
}
{'fraction_non_alphanumeric': 0.19812526629740093, 'fraction_numerical': 0.028547081380485728, 'mean_word_length': 4.276404494382023, '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': '4985896', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1011, 'n_words': 253}