<commit_before>/**
 * FreeRDP: A Remote Desktop Protocol Client
 * File Utils
 *
 * Copyright 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

#include <freerdp/types.h>
#include <freerdp/settings.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/string.h>

#ifndef _WIN32
#include <unistd.h>
#else
#include <direct.h>
#define getcwd			_getcwd
#endif

#include <freerdp/utils/file.h>

#ifndef _WIN32
#define PATH_SEPARATOR_STR	"/"
#define PATH_SEPARATOR_CHR	'/'
#define HOME_ENV_VARIABLE	"HOME"
#else
#include <windows.h>
#define PATH_SEPARATOR_STR	"\\"
#define PATH_SEPARATOR_CHR	'\\'
#define HOME_ENV_VARIABLE	"HOMEPATH"
#endif

#ifdef _WIN32
#define SHARED_LIB_SUFFIX	".dll"
#elif __APPLE__
#define SHARED_LIB_SUFFIX	".dylib"
#else
#define SHARED_LIB_SUFFIX	".so"
#endif

#define FREERDP_CONFIG_DIR	".freerdp"

#define PARENT_PATH		".." PATH_SEPARATOR_STR

void freerdp_mkdir(char* path)
{
#ifndef _WIN32
		mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR);
#else
		CreateDirectoryA(path, 0);
#endif
}

boolean freerdp_check_file_exists(char* file)
{
	struct stat stat_info;

	if (stat(file, &stat_info) != 0)
		return false;

	return true;
}

char* freerdp_get_home_path(rdpSettings* settings)
{
	if (settings->home_path == NULL)
		settings->home_path = getenv(HOME_ENV_VARIABLE);
<commit_msg>If HOME environment variable is not configured, use / as home. Having NULL home_path will crash freerdp.<commit_after>/**
 * FreeRDP: A Remote Desktop Protocol Client
 * File Utils
 *
 * Copyright 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

#include <freerdp/types.h>
#include <freerdp/settings.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/string.h>

#ifndef _WIN32
#include <unistd.h>
#else
#include <direct.h>
#define getcwd			_getcwd
#endif

#include <freerdp/utils/file.h>

#ifndef _WIN32
#define PATH_SEPARATOR_STR	"/"
#define PATH_SEPARATOR_CHR	'/'
#define HOME_ENV_VARIABLE	"HOME"
#else
#include <windows.h>
#define PATH_SEPARATOR_STR	"\\"
#define PATH_SEPARATOR_CHR	'\\'
#define HOME_ENV_VARIABLE	"HOMEPATH"
#endif

#ifdef _WIN32
#define SHARED_LIB_SUFFIX	".dll"
#elif __APPLE__
#define SHARED_LIB_SUFFIX	".dylib"
#else
#define SHARED_LIB_SUFFIX	".so"
#endif

#define FREERDP_CONFIG_DIR	".freerdp"

#define PARENT_PATH		".." PATH_SEPARATOR_STR

void freerdp_mkdir(char* path)
{
#ifndef _WIN32
		mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR);
#else
		CreateDirectoryA(path, 0);
#endif
}

boolean freerdp_check_file_exists(char* file)
{
	struct stat stat_info;

	if (stat(file, &stat_info) != 0)
		return false;

	return true;
}

char* freerdp_get_home_path(rdpSettings* settings)
{
	if (settings->home_path == NULL)
		settings->home_path = getenv(HOME_ENV_VARIABLE);
	if (settings->home_path == NULL)
		settings->home_path = xstrdup("/");

{'fraction_non_alphanumeric': 0.1143357518138604, 'fraction_numerical': 0.009006755066299724, 'mean_word_length': 4.836496350364963, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3590161', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1457, 'n_words': 412}