<commit_before>#include "platform.hpp"

#include "../base/logging.hpp"

#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

//static bool GetUserWritableDir(string & outDir)
//{
//  char * path = ::getenv("HOME");
//  if (path)
//  {
//    outDir = path;
//    outDir += "/.MapsWithMe/";
//    ::mkdir(outDir.c_str(), 0755);
//    return true;
//  }
//  return false;
//}

/// @return directory where binary resides, including slash at the end
static bool GetBinaryFolder(string & outPath)
{
  char path[4096] = {0};
  if (0 < ::readlink("/proc/self/exe", path, ARRAY_SIZE(path)))
  {
    outPath = path;
    outPath.erase(outPath.find_last_of('/') + 1);
    return true;
  }
  return false;
}

Platform::Platform()
{
  // init directories
  string path;
  CHECK(GetBinaryFolder(path), ("Can't retrieve path to executable"));

  // @TODO implement correct resources and writable directories for public releases
  m_resourcesDir = path + "../../data/";
  m_writableDir = m_resourcesDir;
  m_settingsDir = m_writableDir;
  char * tmpDir = ::getenv("TMPDIR");
  if (tmpDir)
    m_tmpDir = tmpDir;
  else
    m_tmpDir = P_tmpdir;

  LOG(LDEBUG, ("Resources directory:", m_resourcesDir));
  LOG(LDEBUG, ("Writable directory:", m_writableDir));
  LOG(LDEBUG, ("Tmp directory:", m_tmpDir));
  LOG(LDEBUG, ("Settings directory:", m_settingsDir));
}

Platform::~Platform()
{<commit_msg>[linux] Fixed build error<commit_after>#include "platform.hpp"

#include "../base/logging.hpp"

#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

//static bool GetUserWritableDir(string & outDir)
//{
//  char * path = ::getenv("HOME");
//  if (path)
//  {
//    outDir = path;
//    outDir += "/.MapsWithMe/";
//    ::mkdir(outDir.c_str(), 0755);
//    return true;
//  }
//  return false;
//}

/// @return directory where binary resides, including slash at the end
static bool GetBinaryFolder(string & outPath)
{
  char path[4096] = {0};
  if (0 < ::readlink("/proc/self/exe", path, ARRAY_SIZE(path)))
  {
    outPath = path;
    outPath.erase(outPath.find_last_of('/') + 1);
    return true;
  }
  return false;
}

Platform::Platform()
{
  // init directories
  string path;
  CHECK(GetBinaryFolder(path), ("Can't retrieve path to executable"));

  // @TODO implement correct resources and writable directories for public releases
  m_resourcesDir = path + "../../data/";
  m_writableDir = m_resourcesDir;
  m_settingsDir = m_writableDir;
  char * tmpDir = ::getenv("TMPDIR");
  if (tmpDir)
    m_tmpDir = tmpDir;
  else
    m_tmpDir = "/tmp";
  m_tmpDir += '/';

  LOG(LDEBUG, ("Resources directory:", m_resourcesDir));
  LOG(LDEBUG, ("Writable directory:", m_writableDir));
  LOG(LDEBUG, ("Tmp directory:", m_tmpDir));
  LOG(LDEBUG, ("Settings directory:", m_settingsDir));
}

Platform::~Platform()
{
{'fraction_non_alphanumeric': 0.1750445632798574, 'fraction_numerical': 0.00784313725490196, 'mean_word_length': 3.6688851913477536, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5420313', 'n_tokens_mistral': 1008, 'n_tokens_neox': 979, 'n_words': 232}