<commit_before>#define _GNU_SOURCE // for strchrnul()
#include <assert.h>

#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

// If this system does not have strchrnul(),
// see ExM c-utils strchrnul.h
#include <config.h>
#include <strchrnul.h>

#include "MPIX_Comm_launch.h"

static char* old_pwd = NULL;

static char* info_get_launcher(MPI_Info info) {
	char* launcher; int flag = 0;
	if(MPI_INFO_NULL != info) {
		int len = 0;
		MPI_Info_get_valuelen(info, "launcher", &len, &flag);
		if(flag) {
			launcher = (char*)malloc(sizeof(char)*(len+1));
			MPI_Info_get(info,"launcher",len+1,launcher,&flag);
		}
	}
	if(!flag) {
		launcher = (char*)malloc(sizeof(char)*(strlen(MPI_DEFAULT_LAUNCHER)+1));
		strcpy(launcher,MPI_DEFAULT_LAUNCHER);
	}
	return launcher;
}

static char* info_get_output_redirection(MPI_Info info) {
	char* redirect; int flag = 0;
	if(MPI_INFO_NULL != info) {
		int len = 0;
		MPI_Info_get_valuelen(info, "output", &len, &flag);
		if(flag) {
			char filename[len+1];

			MPI_Info_get(info,"output",len+1,filename,&flag);
			redirect = (char*)malloc(sizeof(char)*(len+16));
			sprintf(redirect,"1> %s 2>&1",filename);
		}
	}
	if(!flag) {
		redirect = (char*)malloc(sizeof(char));
		redirect[0] = '\0';
	}
	return redirect;
}

static void info_get_envs_error(MPI_Comm comm, const char* message);

/**
 * Return 1 on success, 0 on error.
 * OUT: envs, envs_length
 * If there are no environment variables, *envs=NULL, envs_length=0.
 * Reads info object, puts all environment variables in envs,
 * envs_length is number of environment variables found.
 * */
static int info_get_envs(MPI_Comm comm, MPI_Info info,
		char** envs, size_t* envs_length) {
	int flag = 0;
	char* result;
	if(MPI_INFO_NULL == info) {
		*envs = NULL;
		*envs_length = 0;
		return 1;
	}
	int len = 0;
	MPI_Info_get_valuelen(info, "envs", &len, &flag);
	if(!flag) {
		*envs = NULL;
		*envs_length = 0;
		return 1;
	}
	char count_string[len+1];
	MPI_Info_get(info,"envs",len+1,count_string,&flag);
	long count = strtod(count_string, NULL);
	int* lengths = alloca(count * sizeof(int));
	char* env_word = "env ";
	size_t env_word_length = strlen(env_word);
	size_t total = env_word_length;
	char key[16];
	int i;
	for(i=0; i<count; i++) {
		sprintf(key, "<KEY>
		MPI_Info_get_valuelen(info, key, &len, &flag);
		if(!flag) info_get_envs_error(comm, key);
		lengths[i] = len;
		total += len+2;
	}
	result = malloc(total);
	memset(result, 0, total);
	strcpy(result, env_word);
	char* p = result+env_word_length;
	for(i=0; i<count; i++) {
		sprintf(key, "env%i", i);
		MPI_Info_get(info,key,lengths[i],p,&flag);
		p += lengths[i];
		*p = ' ';<commit_msg>This memset should be unnecessary<commit_after>#define _GNU_SOURCE // for strchrnul()
#include <assert.h>

#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

// If this system does not have strchrnul(),
// see ExM c-utils strchrnul.h
#include <config.h>
#include <strchrnul.h>

#include "MPIX_Comm_launch.h"

static char* old_pwd = NULL;

static char* info_get_launcher(MPI_Info info) {
	char* launcher; int flag = 0;
	if(MPI_INFO_NULL != info) {
		int len = 0;
		MPI_Info_get_valuelen(info, "launcher", &len, &flag);
		if(flag) {
			launcher = (char*)malloc(sizeof(char)*(len+1));
			MPI_Info_get(info,"launcher",len+1,launcher,&flag);
		}
	}
	if(!flag) {
		launcher = (char*)malloc(sizeof(char)*(strlen(MPI_DEFAULT_LAUNCHER)+1));
		strcpy(launcher,MPI_DEFAULT_LAUNCHER);
	}
	return launcher;
}

static char* info_get_output_redirection(MPI_Info info) {
	char* redirect; int flag = 0;
	if(MPI_INFO_NULL != info) {
		int len = 0;
		MPI_Info_get_valuelen(info, "output", &len, &flag);
		if(flag) {
			char filename[len+1];

			MPI_Info_get(info,"output",len+1,filename,&flag);
			redirect = (char*)malloc(sizeof(char)*(len+16));
			sprintf(redirect,"1> %s 2>&1",filename);
		}
	}
	if(!flag) {
		redirect = (char*)malloc(sizeof(char));
		redirect[0] = '\0';
	}
	return redirect;
}

static void info_get_envs_error(MPI_Comm comm, const char* message);

/**
 * Return 1 on success, 0 on error.
 * OUT: envs, envs_length
 * If there are no environment variables, *envs=NULL, envs_length=0.
 * Reads info object, puts all environment variables in envs,
 * envs_length is number of environment variables found.
 * */
static int info_get_envs(MPI_Comm comm, MPI_Info info,
		char** envs, size_t* envs_length) {
	int flag = 0;
	char* result;
	if(MPI_INFO_NULL == info) {
		*envs = NULL;
		*envs_length = 0;
		return 1;
	}
	int len = 0;
	MPI_Info_get_valuelen(info, "envs", &len, &flag);
	if(!flag) {
		*envs = NULL;
		*envs_length = 0;
		return 1;
	}
	char count_string[len+1];
	MPI_Info_get(info,"envs",len+1,count_string,&flag);
	long count = strtod(count_string, NULL);
	int* lengths = alloca(count * sizeof(int));
	char* env_word = "env ";
	size_t env_word_length = strlen(env_word);
	size_t total = env_word_length;
	char key[16];
	int i;
	for(i=0; i<count; i++) {
		sprintf(key, "<KEY>
		MPI_Info_get_valuelen(info, key, &len, &flag);
		if(!flag) info_get_envs_error(comm, key);
		lengths[i] = len;
		total += len+2;
	}
	result = malloc(total+1);
	strcpy(result, env_word);
	char* p = result+env_word_length;
	for(i=0; i<count; i++) {
		sprintf(key, "<KEY>);
		MPI_Info_get(info,key,lengths[i],p,&flag);
		p += lengths[i];
		*p = ' ';
{'fraction_non_alphanumeric': 0.1640466062511559, 'fraction_numerical': 0.012206399112261884, 'mean_word_length': 4.9298245614035086, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '406392', 'n_tokens_mistral': 2366, 'n_tokens_neox': 2228, 'n_words': 478}