<commit_before>// Copyright (C) 2018 <NAME>
// This file is part of the Ouzel engine.

#include "core/Setup.h"

#if !OUZEL_PLATFORM_WINDOWS
#include <fcntl.h>
#include <unistd.h>
#endif
#include "File.hpp"

namespace ouzel
{
    File::File()
    {
    }

    File::File(const std::string& filename, int mode)
    {
        open(filename, mode);
    }

    File::~File()
    {
        close();
    }

    File::File(File&& other)
    {
#if OUZEL_PLATFORM_WINDOWS
        file = other.file;
        other.file = nullptr;
#else
        fd = other.fd;
        other.fd = -1;
#endif
    }

    File& File::operator=(File&& other)
    {
        if (&other != this)
        {
#if OUZEL_PLATFORM_WINDOWS
            if (file != INVALID_HANDLE_VALUE) CloseHandle(file);
            file = other.file;
            other.file = nullptr;
#else
            if (fd != -1) ::close(fd);
            fd = other.fd;
            other.fd = -1;
#endif
        }

        return *this;
    }

    bool File::open(const std::string& filename, int mode)
    {
#if OUZEL_PLATFORM_WINDOWS
        DWORD access = 0;
        if (mode & READ) access |= GENERIC_READ;
        if (mode & WRITE) access |= GENERIC_WRITE;
        if (mode & APPEND) access |= FILE_APPEND_DATA;<commit_msg>Close the file before opening a new one in File::open<commit_after>// Copyright (C) 2018 <NAME>
// This file is part of the Ouzel engine.

#include "core/Setup.h"

#if !OUZEL_PLATFORM_WINDOWS
#include <fcntl.h>
#include <unistd.h>
#endif
#include "File.hpp"

namespace ouzel
{
    File::File()
    {
    }

    File::File(const std::string& filename, int mode)
    {
        open(filename, mode);
    }

    File::~File()
    {
        close();
    }

    File::File(File&& other)
    {
#if OUZEL_PLATFORM_WINDOWS
        file = other.file;
        other.file = nullptr;
#else
        fd = other.fd;
        other.fd = -1;
#endif
    }

    File& File::operator=(File&& other)
    {
        if (&other != this)
        {
#if OUZEL_PLATFORM_WINDOWS
            if (file != INVALID_HANDLE_VALUE) CloseHandle(file);
            file = other.file;
            other.file = nullptr;
#else
            if (fd != -1) ::close(fd);
            fd = other.fd;
            other.fd = -1;
#endif
        }

        return *this;
    }

    bool File::open(const std::string& filename, int mode)
    {
#if OUZEL_PLATFORM_WINDOWS
        if (file != INVALID_HANDLE_VALUE)
        {
            CloseHandle(file);
            file = INVALID_HANDLE_VALUE;
        }
#else
        if (fd != -1)
        {
            ::close(fd);
            fd = -1;
        }
#endif

#if OUZEL_PLATFORM_WINDOWS
        DWORD access = 0;
        if (mode & READ) access |= GENERIC_READ;
        if (mode & WRITE) access |= GENERIC_WRITE;
        if (mode & APPEND) access |= FILE_APPEND_DATA;
{'fraction_non_alphanumeric': 0.13108348134991119, 'fraction_numerical': 0.006394316163410302, 'mean_word_length': 1.9060887512899898, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3058346', 'n_tokens_mistral': 999, 'n_tokens_neox': 971, 'n_words': 232}