Use HOST_NAME_MAX instead of hardcoding the maximum hostname length
This commit is contained in:
@@ -100,7 +100,7 @@ if(X264_FOUND)
|
||||
target_link_libraries(wivrn-server PRIVATE PkgConfig::X264)
|
||||
endif()
|
||||
|
||||
if(SYSTEMD_FOUND)
|
||||
if(WIVRN_USE_SYSTEMD)
|
||||
target_sources(wivrn-server PRIVATE hostname-sd.cpp)
|
||||
target_link_libraries(wivrn-server PRIVATE PkgConfig::SYSTEMD)
|
||||
else()
|
||||
|
||||
+6
-6
@@ -1,13 +1,13 @@
|
||||
#include "hostname.h"
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
std::string hostname()
|
||||
{
|
||||
char buf[256];
|
||||
int code = gethostname(buf, 256);
|
||||
if (code == 0)
|
||||
return std::string(buf);
|
||||
return "unknown";
|
||||
char buf[HOST_NAME_MAX];
|
||||
int code = gethostname(buf, HOST_NAME_MAX);
|
||||
if (code == 0)
|
||||
return buf;
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user