<commit_before>#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <resolv.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "logger.h"
#include "nss_getdns.h"
#include "opt_parse.h"
#include "addr_utils.h"

#define  UNUSED_PARAM(x) ((void)(x))

extern int log_level;

/*
*Create/load context.
*The context should be reused per process.
*It must therefore be safe to be used for multiple threads.
*If given a non-NULL context, no other context will be created. So a request for a new context must pass in a NULL ctx
*If a non-NULL extensions is given, a new one will be created only if the configuration file has changed.
*NOTE: This context is maintained by one process. Not safe for forks.
*/
getdns_return_t load_context(getdns_context **ctx, getdns_dict **ext, time_t *last_check)
{
	getdns_return_t return_code = GETDNS_RETURN_GOOD;
	getdns_dict *extensions = NULL;
	getdns_context *context = NULL;
	int config_update = 0;
	if((*ctx != NULL) && (*ext != NULL) && (last_check != NULL))
	{
		struct stat st;
		if(stat(CONFIG_FILE_LOCAL, &st) != 0)
		{
			log_warning("load_context< %s >", strerror(errno));
		}else if(difftime(*last_check, st.st_mtime) > 0){
			log_info("load_context< loading new settings from %s >", CONFIG_FILE_LOCAL);
			*last_check = st.st_mtime;
			config_update = 1;
		}
		UNUSED_PARAM(st);
	}
	/*
	*Initialize library configuration from config file (getdns.conf or user's local preferences)
	*/<commit_msg>looking for preferences file in home directory. Reloading context when file is newer.<commit_after>#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <resolv.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include "logger.h"
#include "nss_getdns.h"
#include "opt_parse.h"
#include "addr_utils.h"

#define  UNUSED_PARAM(x) ((void)(x))

extern int log_level;

/*
*Create/load context.
*The context should be reused per process.
*It must therefore be safe to be used for multiple threads.
*If given a non-NULL context, no other context will be created. So a request for a new context must pass in a NULL ctx
*If a non-NULL extensions is given, a new one will be created only if the configuration file has changed.
*NOTE: This context is maintained by one process. Not safe for forks.
*/
getdns_return_t load_context(getdns_context **ctx, getdns_dict **ext, time_t *last_check)
{
	getdns_return_t return_code = GETDNS_RETURN_GOOD;
	getdns_dict *extensions = NULL;
	getdns_context *context = NULL;
	int config_update = 0;
	if((*ctx != NULL) && (*ext != NULL) && (last_check != NULL))
	{
		struct stat st;
		char config_file[256];
		snprintf(config_file, 256, "%s/%s/%s.conf", getenv("HOME"), ".getdns", CONFIG_FILE_LOCAL);
		if(stat(config_file, &st) != 0)
		{
			log_warning("load_context< %s >", strerror(errno));
		}else if(difftime(st.st_mtime, *last_check) > 0){
			log_info("load_context< loading new settings from %s >", config_file);
			*last_check = st.st_mtime;
			config_update = 1;
		}
		UNUSED_PARAM(st);
	}
	/*
	*Initialize library configuration from config file (getdns.conf or user's local preferences)
	*/
{'fraction_non_alphanumeric': 0.12915129151291513, 'fraction_numerical': 0.004305043050430504, 'mean_word_length': 4.788256227758007, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 28, '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': '837453', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1163, 'n_words': 358}