<commit_before>#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

#include "memory.h"
#include "../util/file_utils.h"


long total_memory(void)
{
    char *memory = proc_parser(MEMINFO, TOTALMEM);

    if (memory != NULL) {
        long value = strtol(memory, NULL, 10);
        free(memory);
        return value;
    }

    return -1;
}

float memory_percentage(char *pidstr, long totalmem)
{
    float total_usage, total_mem_percent;

    size_t path_length = strlen(pidstr) + STATUS_LEN;
    char *path = malloc(sizeof(char) * path_length + 1);

    snprintf(path, path_length, STATUS, pidstr);

    char *percentage = proc_parser(path, VMEM);

    if (percentage != NULL) {
        total_usage = (float) strtol(percentage, NULL, 10);
        free(percentage);
        total_mem_percent = (total_usage / totalmem) * 100;
    } else 
        total_mem_percent = MINMEM;
    
    free(path);

    return total_mem_percent;
}<commit_msg>No longer build path with malloc<commit_after>#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#include "memory.h"
#include "../util/file_utils.h"


long total_memory(void)
{
    char *memory = proc_parser(MEMINFO, TOTALMEM);

    if (memory != NULL) {
        long value = strtol(memory, NULL, 10);
        free(memory);
        return value;
    }

    return -1;
}

float memory_percentage(char *path, long totalmem)
{
    float total_usage, total_mem_percent;

    char *percentage = proc_parser(path, VMEM);

    if (percentage != NULL) {
        total_usage = (float) strtol(percentage, NULL, 10);
        free(percentage);
        total_mem_percent = (total_usage / totalmem) * 100;
    } else 
        total_mem_percent = MINMEM;
    
    return total_mem_percent;
}
{'fraction_non_alphanumeric': 0.124, 'fraction_numerical': 0.009714285714285713, 'mean_word_length': 3.043879907621247, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2182593', 'n_tokens_mistral': 627, 'n_tokens_neox': 585, 'n_words': 139}