<commit_before>/*
 * Copyright (C) 2010-2016 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "pfile.h"
#include "plibsys-private.h"

#ifdef P_OS_WIN
#include <windows.h>
#else
#include <unistd.h>
#endif

P_LIB_API pboolean
p_file_is_exists (const pchar *file)
{
#ifdef P_OS_WIN
	DWORD attrs;
#endif

	if (file == NULL)
		return FALSE;

#ifdef P_OS_WIN
	attrs = GetFileAttributesA ((LPCSTR) file);

	return (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY) == 0);
#else
	return access (file, F_OK) == 0;
#endif
}

P_LIB_API pboolean
p_file_remove (const pchar	*file,
	       PError		**error)
{
	pboolean result;

	if (file == NULL) {
		p_error_set_error_p (error,
				     (pint) P_ERROR_IO_INVALID_ARGUMENT,
				     0,
				     "Invalid input argument");
		return FALSE;
	}

#ifdef P_OS_WIN
	result = (DeleteFileA ((LPCSTR) file) != 0);
#else
	result = (unlink (file) == 0);
#endif

	if (!result)
		p_error_set_error_p (error,
				     (pint) __p_error_get_last_io (),
				     __p_error_get_last_error (),
				     "Failed to remove file");

	return result;
}<commit_msg>Add P_LIKELY() optimizations to file routines<commit_after>/*
 * Copyright (C) 2010-2016 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "pfile.h"
#include "plibsys-private.h"

#ifdef P_OS_WIN
#include <windows.h>
#else
#include <unistd.h>
#endif

P_LIB_API pboolean
p_file_is_exists (const pchar *file)
{
#ifdef P_OS_WIN
	DWORD attrs;
#endif

	if (P_UNLIKELY (file == NULL))
		return FALSE;

#ifdef P_OS_WIN
	attrs = GetFileAttributesA ((LPCSTR) file);

	return (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY) == 0);
#else
	return access (file, F_OK) == 0;
#endif
}

P_LIB_API pboolean
p_file_remove (const pchar	*file,
	       PError		**error)
{
	pboolean result;

	if (P_UNLIKELY (file == NULL)) {
		p_error_set_error_p (error,
				     (pint) P_ERROR_IO_INVALID_ARGUMENT,
				     0,
				     "Invalid input argument");
		return FALSE;
	}

#ifdef P_OS_WIN
	result = (DeleteFileA ((LPCSTR) file) != 0);
#else
	result = (unlink (file) == 0);
#endif

	if (P_UNLIKELY (!result))
		p_error_set_error_p (error,
				     (pint) __p_error_get_last_io (),
				     __p_error_get_last_error (),
				     "Failed to remove file");

	return result;
}
{'fraction_non_alphanumeric': 0.1033210332103321, 'fraction_numerical': 0.007947771785410162, 'mean_word_length': 3.7815468113975577, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '1940183', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1181, 'n_words': 410}