Fix FreeBSD compilation

This commit is contained in:
John Sennesael 2021-10-24 20:04:12 +06:00
parent 319bc9e436
commit 4be3dfcd77
8 changed files with 39 additions and 10 deletions

View File

@ -32,6 +32,11 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND COMMON_LIBRARIES "stdc++fs")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Usenetsearch common library -------------------------------------------------- # Usenetsearch common library --------------------------------------------------
add_library(usenetsearch add_library(usenetsearch
@ -60,7 +65,7 @@ target_include_directories(usenetsearch
) )
target_link_libraries(usenetsearch target_link_libraries(usenetsearch
PUBLIC ${OPENSSL_LIBRARIES} stdc++fs PUBLIC ${OPENSSL_LIBRARIES} ${COMMON_LIBRARIES}
) )
# Indexer executable ----------------------------------------------------------- # Indexer executable -----------------------------------------------------------
@ -70,7 +75,7 @@ add_executable(usenetindexd
) )
target_link_libraries(usenetindexd target_link_libraries(usenetindexd
PUBLIC ${OPENSSL_LIBRARIES} stdc++fs PUBLIC ${OPENSSL_LIBRARIES} ${COMMON_LIBRARIES}
PRIVATE usenetsearch PRIVATE usenetsearch
) )
@ -86,7 +91,7 @@ add_executable(usenetfind
) )
target_link_libraries(usenetfind target_link_libraries(usenetfind
PUBLIC ${OPENSSL_LIBRARIES} stdc++fs PUBLIC ${OPENSSL_LIBRARIES} ${COMMON_LIBRARIES}
PRIVATE usenetsearch PRIVATE usenetsearch
) )
@ -102,7 +107,7 @@ add_executable(dbdump
) )
target_link_libraries(dbdump target_link_libraries(dbdump
PUBLIC ${OPENSSL_LIBRARIES} stdc++fs PUBLIC ${OPENSSL_LIBRARIES} ${COMMON_LIBRARIES}
PRIVATE usenetsearch PRIVATE usenetsearch
) )

View File

@ -21,6 +21,7 @@
#include "usenetsearch/Serialize.h" #include "usenetsearch/Serialize.h"
#include "usenetsearch/UsenetClient.h" #include "usenetsearch/UsenetClient.h"
#include <array>
#include <codecvt> #include <codecvt>
#include <cstdint> #include <cstdint>
#include <filesystem> #include <filesystem>

View File

@ -18,6 +18,7 @@
#pragma once #pragma once
#include <stdexcept> #include <stdexcept>
#include <string>
namespace usenetsearch { namespace usenetsearch {

View File

@ -85,8 +85,15 @@ template<typename T>
T StringLeftTrim(const T& str) T StringLeftTrim(const T& str)
{ {
T s = str; T s = str;
s.erase(s.begin(), std::find_if(s.begin(), s.end(), s.erase(s.begin(),
std::not1(std::ptr_fun<int, int>(std::isspace)))); std::find_if(
s.begin(),
s.end(),
[](char c){
return !std::isspace(c);
}
)
);
return s; return s;
} }
@ -105,10 +112,15 @@ T StringRemove(const T& subject, const T& toErase)
template<typename T> template<typename T>
T StringRightTrim(const T& str) T StringRightTrim(const T& str)
{ {
T s = str; T s(str);
s.erase(std::find_if(s.rbegin(), s.rend(), s.erase(std::find_if(
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.rbegin(),
s.end()); s.rend(),
[](unsigned char c){
return !std::isspace(c);
}
).base(), s.end()
);
return s; return s;
} }

View File

@ -19,6 +19,8 @@
#include "usenetsearch/Logger.h" #include "usenetsearch/Logger.h"
#include <sys/socket.h>
#include <cerrno> #include <cerrno>
#include <thread> #include <thread>

View File

@ -127,7 +127,11 @@ void SerializableFile::Close()
void SerializableFile::Open(const std::string& fileName) void SerializableFile::Open(const std::string& fileName)
{ {
#ifdef __linux__
const int flags{O_RDWR|O_NOATIME|O_CREAT}; const int flags{O_RDWR|O_NOATIME|O_CREAT};
#else
const int flags{O_RDWR|O_CREAT};
#endif
int ret = open(fileName.c_str(), flags, 0644); int ret = open(fileName.c_str(), flags, 0644);
if (ret < 0) if (ret < 0)
{ {

View File

@ -22,11 +22,13 @@
#include <openssl/md5.h> #include <openssl/md5.h>
#include <algorithm> #include <algorithm>
#include <array>
#include <codecvt> #include <codecvt>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <locale> #include <locale>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -20,6 +20,8 @@
#include "usenetsearch/Dns.h" #include "usenetsearch/Dns.h"
#include <netinet/in.h> // sockaddr_in
#include <sys/socket.h> // AF_INET etc...
#include <unistd.h> // close(), read(), write() #include <unistd.h> // close(), read(), write()
#include <cerrno> #include <cerrno>