<commit_before>/**
 * fs.c
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 */

#include "fs.h"

/**
 * Get pointer to directory by its pathname.
 */
DIR *get_dir (const char *path) {
	DIR *dp;

	if (!(dp = opendir(path))) {
		printf("Error opening directory %s\n", path);

		exit(EXIT_FAILURE);
	}

	printf("get_dir -> path -> %s\n", path);

	return dp;
}

/**
 * Get pointer to file by its pathname.
 */
FILE *get_file (char *filename, char *filemode) {
	FILE *fp = fopen(filename, filemode);

	if (!fp) {
		printf("Error opening file %s\n", filename);

		exit(EXIT_FAILURE);
	}

	printf("get_file -> filename -> %s\n", filename);

	return fp;
}

/**
 * Determine if pathname is a directory.
 *
 * @notes Adapted from https://goo.gl/ZmWfbx
 */
int is_dir (const char *path) {
	DIR *dp = get_dir(path);
	struct dirent *de;
	int is_dir;
	char actualpath[PATH_MAX], *dir_ptr;

	// Absolute path to directory
	dir_ptr = realpath(path, actualpath);

	printf("is_dir -> path -> %s\n", dir_ptr);

	while ((de = readdir(dp))) {
	#ifdef _DIRENT_HAVE_D_TYPE
		if (de->d_type != DT_UNKNOWN && de->d_type != DT_LNK) {
			is_dir = (de->d_type == DT_DIR) ? 1 : 0;
		} else
	#endif
		{
			struct stat st;

			stat(de->d_name, &st);
			is_dir = S_ISDIR(st.st_mode);
		}

		if (is_dir) {
			printf("is_dir -> de->d_name -> %s/\n", de->d_name);

			return 1;
		}
	}

	return 0;
}

/**
 * Determine if pathname is a regular file.
 *
 * @notes Adapted from https://goo.gl/ZmWfbx
 */
int is_file (const char *path) {
	struct stat st;

	if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) {<commit_msg>Remove unused debugging output<commit_after>/**
 * fs.c
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 */

#include "fs.h"

/**
 * Get pointer to directory by its pathname.
 */
DIR *get_dir (const char *path) {
	DIR *dp;

	if (!(dp = opendir(path))) {
		printf("Error opening directory %s\n", path);

		exit(EXIT_FAILURE);
	}

	return dp;
}

/**
 * Get pointer to file by its pathname.
 */
FILE *get_file (char *filename, char *filemode) {
	FILE *fp = fopen(filename, filemode);

	if (!fp) {
		printf("Error opening file %s\n", filename);

		exit(EXIT_FAILURE);
	}

	return fp;
}

/**
 * Determine if pathname is a directory.
 *
 * @notes Adapted from https://goo.gl/ZmWfbx
 */
int is_dir (const char *path) {
	DIR *dp = get_dir(path);
	struct dirent *de;
	int is_dir;
	char actualpath[PATH_MAX], *dir_ptr;

	while ((de = readdir(dp))) {
	#ifdef _DIRENT_HAVE_D_TYPE
		if (de->d_type != DT_UNKNOWN && de->d_type != DT_LNK) {
			is_dir = (de->d_type == DT_DIR);
		} else
	#endif
		{
			struct stat st;

			stat(de->d_name, &st);
			is_dir = S_ISDIR(st.st_mode);
		}

		if (is_dir) {
			return 1;
		}
	}

	return 0;
}

/**
 * Determine if pathname is a regular file.
 *
 * @notes Adapted from https://goo.gl/ZmWfbx
 */
int is_file (const char *path) {
	struct stat st;

	if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) {
{'fraction_non_alphanumeric': 0.17388292344994805, 'fraction_numerical': 0.005542085209560097, 'mean_word_length': 3.2037845705967976, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 4, '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': '3325605', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1163, 'n_words': 306}