<commit_before>/*******************************************************************************
 *
 * kit/kernel/archive.c
 * - kit archive (init files) loader
 *
 * vim:ts=2:sw=2:et:tw=80:ft=c
 *
 * Copyright (C) 2015, <NAME>
 * Redistribution of this file is permitted under the terms of the simplified
 * BSD license. See LICENSE for more information.
 *
 ******************************************************************************/

#include "archive.h"
#include "memory.h"
#include "string.h"
#include "debug.h"

bool archive_initialize(uint64_t modules_count, multiboot_module_t *modules)
{
  for (uint32_t i = 0; i < modules_count; i++)
  {
    char *cmdline = (modules[i].cmdline == 0 ? NULL :
                     (char *) KERNEL_OFFSET + modules[i].cmdline);

    if (cmdline != NULL)
    {
      if (string_compare(cmdline, ARCHIVE_SYSTEM_NAME) == 0)
      {
        archive_system = (archive_header_t *)
          (KERNEL_OFFSET + modules[i].mod_start);

        return true;
      }
    }
  }

  DEBUG_MESSAGE(ARCHIVE_SYSTEM_NAME " not found");

  return false;
}

bool archive_get(archive_header_t *header, const char *entry_name,
    char **buffer, uint64_t *length)
{
  size_t entry_name_length = string_length(entry_name);

  archive_iterator_t iterator = archive_iterate(header);

  archive_entry_t *entry;

  while ((entry = archive_next(&iterator)) != NULL)
  {
    if (memory_compare(&entry->name, entry_name,
          (entry_name_length > entry->name_length ?
           entry->name_length : entry_name_length)) == 0)
    {
      *buffer = ((char *) header) + entry->offset;
      *length = entry->length;

      return true;
    }
  }

  return false;
}<commit_msg>[archive] fix archive_get()'s string matching logic (was only matching prefix)<commit_after>/*******************************************************************************
 *
 * kit/kernel/archive.c
 * - kit archive (init files) loader
 *
 * vim:ts=2:sw=2:et:tw=80:ft=c
 *
 * Copyright (C) 2015, <NAME>
 * Redistribution of this file is permitted under the terms of the simplified
 * BSD license. See LICENSE for more information.
 *
 ******************************************************************************/

#include "archive.h"
#include "memory.h"
#include "string.h"
#include "debug.h"

bool archive_initialize(uint64_t modules_count, multiboot_module_t *modules)
{
  for (uint32_t i = 0; i < modules_count; i++)
  {
    char *cmdline = (modules[i].cmdline == 0 ? NULL :
                     (char *) KERNEL_OFFSET + modules[i].cmdline);

    if (cmdline != NULL)
    {
      if (string_compare(cmdline, ARCHIVE_SYSTEM_NAME) == 0)
      {
        archive_system = (archive_header_t *)
          (KERNEL_OFFSET + modules[i].mod_start);

        return true;
      }
    }
  }

  DEBUG_MESSAGE(ARCHIVE_SYSTEM_NAME " not found");

  return false;
}

bool archive_get(archive_header_t *header, const char *entry_name,
    char **buffer, uint64_t *length)
{
  size_t entry_name_length = string_length(entry_name);

  archive_iterator_t iterator = archive_iterate(header);

  archive_entry_t *entry;

  while ((entry = archive_next(&iterator)) != NULL)
  {
    if (entry_name_length == entry->name_length &&
        memory_compare(&entry->name, entry_name, entry_name_length) == 0)
    {
      *buffer = ((char *) header) + entry->offset;
      *length = entry->length;

      return true;
    }
  }

  return false;
}
{'fraction_non_alphanumeric': 0.20732064421669108, 'fraction_numerical': 0.010541727672035138, 'mean_word_length': 3.641304347826087, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6152664', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1036, 'n_words': 242}