<commit_before>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/dynamiclibrary.h>
#include <vespa/fastos/file.h>

#include <dlfcn.h>

namespace {
const std::string FASTOS_DYNLIB_PREFIX("lib");
const std::string FASTOS_DYNLIB_SUFFIX(".so");
const std::string FASTOS_DYNLIB_SUFPREFIX(".so.");

bool hasValidSuffix(const std::string & s)
{
    return (s.rfind(FASTOS_DYNLIB_SUFFIX) == (s.size() - FASTOS_DYNLIB_SUFFIX.size()))
           || (s.rfind(FASTOS_DYNLIB_SUFPREFIX) != std::string::npos);
}

}

void
FastOS_UNIX_DynamicLibrary::SetLibName(const char *libname)
{
    if (libname != nullptr) {
        _libname = libname;
        if ( ! hasValidSuffix(_libname)) {
            _libname.append(FASTOS_DYNLIB_SUFFIX);
        }
    } else {
        _libname = "";
    }
}

bool
FastOS_UNIX_DynamicLibrary::NormalizeLibName(void)
{
    bool returnCode = false;
    std::string::size_type pathPos = _libname.rfind(FastOS_File::GetPathSeparator()[0]);
    std::string tmp = (pathPos != std::string::npos)
                      ? _libname.substr(pathPos+1)
                      : _libname;
    if (tmp.find(FASTOS_DYNLIB_PREFIX) != 0) {
        tmp = FASTOS_DYNLIB_PREFIX + tmp;
        if (pathPos != std::string::npos) {<commit_msg>Handle shared library names on darwin.<commit_after>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/dynamiclibrary.h>
#include <vespa/fastos/file.h>

#include <dlfcn.h>

namespace {
const std::string FASTOS_DYNLIB_PREFIX("lib");
#ifdef __APPLE__
const std::string FASTOS_DYNLIB_SUFFIX(".dylib");
#else
const std::string FASTOS_DYNLIB_SUFFIX(".so");
const std::string FASTOS_DYNLIB_SUFPREFIX(".so.");
#endif

bool hasValidSuffix(const std::string & s)
{
    if (s.rfind(FASTOS_DYNLIB_SUFFIX) == (s.size() - FASTOS_DYNLIB_SUFFIX.size())) {
        return true;
    }
#ifndef __APPLE__
    if (s.rfind(FASTOS_DYNLIB_SUFPREFIX) != std::string::npos) {
        return true;
    }
#endif
    return false;
}

}

void
FastOS_UNIX_DynamicLibrary::SetLibName(const char *libname)
{
    if (libname != nullptr) {
        _libname = libname;
        if ( ! hasValidSuffix(_libname)) {
            _libname.append(FASTOS_DYNLIB_SUFFIX);
        }
    } else {
        _libname = "";
    }
}

bool
FastOS_UNIX_DynamicLibrary::NormalizeLibName(void)
{
    bool returnCode = false;
    std::string::size_type pathPos = _libname.rfind(FastOS_File::GetPathSeparator()[0]);
    std::string tmp = (pathPos != std::string::npos)
                      ? _libname.substr(pathPos+1)
                      : _libname;
    if (tmp.find(FASTOS_DYNLIB_PREFIX) != 0) {
        tmp = FASTOS_DYNLIB_PREFIX + tmp;
        if (pathPos != std::string::npos) {
{'fraction_non_alphanumeric': 0.13281799016163034, 'fraction_numerical': 0.006324666198172874, 'mean_word_length': 3.4414976599063962, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6979091', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1029, 'n_words': 188}