<commit_before>#define CHAZ_USE_SHORT_NAMES

#include <stdlib.h>
#include <string.h>

#include "Charmonizer/Core/Dir.h"

#include "Charmonizer/Core/Compiler.h"
#include "Charmonizer/Core/HeadCheck.h"
#include "Charmonizer/Core/ModHandler.h"
#include "Charmonizer/Core/OperSys.h"
#include "Charmonizer/Core/Util.h"

static chaz_bool_t mkdir_available = false;
static chaz_bool_t rmdir_available = false;
static chaz_bool_t initialized     = false;
int    Dir_mkdir_num_args = 0;
static char mkdir_command[7];
char *Dir_mkdir_command = mkdir_command;

/* Source code for standard POSIX mkdir */
static char posix_mkdir_code[] = METAQUOTE
    #include <%s>
    int main(int argc, char **argv) {
        if (argc != 2) { return 1; }
        if (mkdir(argv[1], 0777) != 0) { return 2; }
        return 0;
    }
METAQUOTE;

/* Source code for Windows _mkdir. */
static char win_mkdir_code[] = METAQUOTE
    #include <direct.h>
    int main(int argc, char **argv) {
        if (argc != 2) { return 1; }
        if (_mkdir(argv[1]) != 0) { return 2; }
        return 0;
    }
METAQUOTE;

/* Source code for rmdir. */
static char rmdir_code[] = METAQUOTE
    #include <%s>
    int main(int argc, char **argv) {
        if (argc != 2) { return 1; }
        if (rmdir(argv[1]) != 0) { return 2; }
        return 0;
    }
METAQUOTE;

static chaz_bool_t
S_try_init_posix_mkdir(char *header)
{
    size_t needed = sizeof(posix_mkdir_code) + 30;
    char *code_buf = (char*)malloc(needed);

    /* Attempt compilation. */
    sprintf(code_buf, posix_mkdir_code, header);
    mkdir_available = ModHand_compiler->compile_exe(ModHand_compiler, "_charm_mkdir.c",
        "_charm_mkdir", code_buf, strlen(code_buf));

    /* Set vars on success. */
    if (mkdir_available) {
        strcpy(mkdir_command, "mkdir");
        if (strcmp(header, "direct.h") == 0) {
            Dir_mkdir_num_args = 1;
        }
        else {
            Dir_mkdir_num_args = 2;
        }
    }

    free(code_buf);
    return mkdir_available;
}

static chaz_bool_t
S_try_init_win_mkdir()
{
    mkdir_available = ModHand_compiler->compile_exe(ModHand_compiler, "_charm_mkdir.c",
        "_charm_mkdir", win_mkdir_code, strlen(win_mkdir_code));
    if (mkdir_available) {
        strcpy(mkdir_command, "_mkdir");
        Dir_mkdir_num_args = 1;
    }
    return mkdir_available;
}

static void
S_init_mkdir()
{
    if (Util_verbosity) {
        printf("Attempting to compile _charm_mkdir utility...\n");
    }
    if (S_try_init_win_mkdir())               { return; }
    if (S_try_init_posix_mkdir("sys/stat.h")) { return; }
    if (S_try_init_posix_mkdir("direct.h"))   { return; }
}<commit_msg>Change order of mkdir Charmonizer probes on Windows to prefer single-arg version over POSIX two-arg version.<commit_after>#define CHAZ_USE_SHORT_NAMES

#include <stdlib.h>
#include <string.h>

#include "Charmonizer/Core/Dir.h"

#include "Charmonizer/Core/Compiler.h"
#include "Charmonizer/Core/HeadCheck.h"
#include "Charmonizer/Core/ModHandler.h"
#include "Charmonizer/Core/OperSys.h"
#include "Charmonizer/Core/Util.h"

static chaz_bool_t mkdir_available = false;
static chaz_bool_t rmdir_available = false;
static chaz_bool_t initialized     = false;
int    Dir_mkdir_num_args = 0;
static char mkdir_command[7];
char *Dir_mkdir_command = mkdir_command;

/* Source code for standard POSIX mkdir */
static char posix_mkdir_code[] = METAQUOTE
    #include <%s>
    int main(int argc, char **argv) {
        if (argc != 2) { return 1; }
        if (mkdir(argv[1], 0777) != 0) { return 2; }
        return 0;
    }
METAQUOTE;

/* Source code for Windows _mkdir. */
static char win_mkdir_code[] = METAQUOTE
    #include <direct.h>
    int main(int argc, char **argv) {
        if (argc != 2) { return 1; }
        if (_mkdir(argv[1]) != 0) { return 2; }
        return 0;
    }
METAQUOTE;

/* Source code for rmdir. */
static char rmdir_code[] = METAQUOTE
    #include <%s>
    int main(int argc, char **argv) {
        if (argc != 2) { return 1; }
        if (rmdir(argv[1]) != 0) { return 2; }
        return 0;
    }
METAQUOTE;

static chaz_bool_t
S_try_init_posix_mkdir(char *header)
{
    size_t needed = sizeof(posix_mkdir_code) + 30;
    char *code_buf = (char*)malloc(needed);

    /* Attempt compilation. */
    sprintf(code_buf, posix_mkdir_code, header);
    mkdir_available = ModHand_compiler->compile_exe(ModHand_compiler, "_charm_mkdir.c",
        "_charm_mkdir", code_buf, strlen(code_buf));

    /* Set vars on success. */
    if (mkdir_available) {
        strcpy(mkdir_command, "mkdir");
        if (strcmp(header, "direct.h") == 0) {
            Dir_mkdir_num_args = 1;
        }
        else {
            Dir_mkdir_num_args = 2;
        }
    }

    free(code_buf);
    return mkdir_available;
}

static chaz_bool_t
S_try_init_win_mkdir()
{
    mkdir_available = ModHand_compiler->compile_exe(ModHand_compiler, "_charm_mkdir.c",
        "_charm_mkdir", win_mkdir_code, strlen(win_mkdir_code));
    if (mkdir_available) {
        strcpy(mkdir_command, "_mkdir");
        Dir_mkdir_num_args = 1;
    }
    return mkdir_available;
}

static void
S_init_mkdir()
{
    if (Util_verbosity) {
        printf("Attempting to compile _charm_mkdir utility...\n");
    }
    if (HeadCheck_check_header("windows.h")) {
        if (S_try_init_win_mkdir())               { return; }
        if (S_try_init_posix_mkdir("direct.h"))   { return; }
    }
    else {
        if (S_try_init_posix_mkdir("sys/stat.h")) { return; }
    }
}
{'fraction_non_alphanumeric': 0.12638863594973593, 'fraction_numerical': 0.010926971407758149, 'mean_word_length': 3.065136935603257, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '6186431', 'n_tokens_mistral': 2127, 'n_tokens_neox': 1973, 'n_words': 428}