<commit_before>#include "ctrcommon/common.hpp"
#include "service.hpp"

#include <sys/dirent.h>
#include <sys/syslimits.h>
#include <sys/unistd.h>
#include <stdio.h>

#include <sstream>

#include <3ds.h>

static FS_archive sdmcArchive = {ARCH_SDMC, {PATH_EMPTY, 1, (u8*) ""}};

const std::string fs_fix_path(const std::string path) {
    std::string fixed = path;
    std::string::size_type colon = fixed.find(':');
    if(colon != std::string::npos) {
        fixed = fixed.substr(colon + 1, std::string::npos);
    }

    if(fixed.find(':') != std::string::npos) {
        return NULL;
    }

    if(fixed[0] == '/') {
        return path;
    }

    static char cwdBuf[PATH_MAX + 1];
    getcwd(cwdBuf, PATH_MAX);

    std::stringstream stream;
    stream << cwdBuf << fixed;
    return stream.str();
}

u64 fs_get_free_space(MediaType mediaType) {
    if(!service_require("fs")) {
        return 0;
    }

    u32 clusterSize;
    u32 freeClusters;
    Result res = 0;
    if(mediaType == NAND) {
        res = FSUSER_GetNandArchiveResource(NULL, NULL, &clusterSize, NULL, &freeClusters);
    } else {
        res = FSUSER_GetSdmcArchiveResource(NULL, NULL, &clusterSize, NULL, &freeClusters);
    }

    if(res != 0) {
        platform_set_error(service_parse_error((u32) res));
        return 0;
    }

    return clusterSize * freeClusters;
}

bool fs_exists(const std::string path) {
    FILE* fd = fopen(path.c_str(), "r");
    if(fd) {
        fclose(fd);
        return true;
    }

    DIR* dir = opendir(path.c_str());
    if(dir) {
        closedir(dir);
        return true;
    }

    return false;
}

bool fs_delete(const std::string path) {
    Result res = FSUSER_DeleteFile(NULL, sdmcArchive, FS_makePath(PATH_CHAR, fs_fix_path(path).c_str()));
    if(res != 0) {
        platform_set_error(service_parse_error((u32) res));
    }

    return res == 0;
}<commit_msg>When getting free space, cast values to u64.<commit_after>#include "ctrcommon/common.hpp"
#include "service.hpp"

#include <sys/dirent.h>
#include <sys/syslimits.h>
#include <sys/unistd.h>
#include <stdio.h>

#include <sstream>

#include <3ds.h>

static FS_archive sdmcArchive = {ARCH_SDMC, {PATH_EMPTY, 1, (u8*) ""}};

const std::string fs_fix_path(const std::string path) {
    std::string fixed = path;
    std::string::size_type colon = fixed.find(':');
    if(colon != std::string::npos) {
        fixed = fixed.substr(colon + 1, std::string::npos);
    }

    if(fixed.find(':') != std::string::npos) {
        return NULL;
    }

    if(fixed[0] == '/') {
        return path;
    }

    static char cwdBuf[PATH_MAX + 1];
    getcwd(cwdBuf, PATH_MAX);

    std::stringstream stream;
    stream << cwdBuf << fixed;
    return stream.str();
}

u64 fs_get_free_space(MediaType mediaType) {
    if(!service_require("fs")) {
        return 0;
    }

    u32 clusterSize;
    u32 freeClusters;
    Result res = 0;
    if(mediaType == NAND) {
        res = FSUSER_GetNandArchiveResource(NULL, NULL, &clusterSize, NULL, &freeClusters);
    } else {
        res = FSUSER_GetSdmcArchiveResource(NULL, NULL, &clusterSize, NULL, &freeClusters);
    }

    if(res != 0) {
        platform_set_error(service_parse_error((u32) res));
        return 0;
    }

    return (u64) clusterSize * (u64) freeClusters;
}

bool fs_exists(const std::string path) {
    FILE* fd = fopen(path.c_str(), "r");
    if(fd) {
        fclose(fd);
        return true;
    }

    DIR* dir = opendir(path.c_str());
    if(dir) {
        closedir(dir);
        return true;
    }

    return false;
}

bool fs_delete(const std::string path) {
    Result res = FSUSER_DeleteFile(NULL, sdmcArchive, FS_makePath(PATH_CHAR, fs_fix_path(path).c_str()));
    if(res != 0) {
        platform_set_error(service_parse_error((u32) res));
    }

    return res == 0;
}

{'fraction_non_alphanumeric': 0.15162644281217208, 'fraction_numerical': 0.013116474291710388, 'mean_word_length': 3.0306553911205074, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, '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': '2064067', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1369, 'n_words': 279}