mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
obtain maximum hostname length via sysconf() in QHostInfo::localHostName()
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
574c3c90fd
commit
606a6b714e
1 changed files with 7 additions and 4 deletions
|
@ -273,10 +273,13 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
|
|||
|
||||
QString QHostInfo::localHostName()
|
||||
{
|
||||
char hostName[HOST_NAME_MAX];
|
||||
if (Q_LIKELY(::gethostname(hostName, sizeof(hostName)) == 0)) {
|
||||
hostName[sizeof(hostName) - 1] = '\0';
|
||||
return QString::fromLocal8Bit(hostName);
|
||||
int size_max = sysconf(_SC_HOST_NAME_MAX);
|
||||
if (size_max == -1)
|
||||
size_max = _POSIX_HOST_NAME_MAX;
|
||||
char gethostbuffer[size_max];
|
||||
if (Q_LIKELY(::gethostname(gethostbuffer, size_max) == 0)) {
|
||||
gethostbuffer[size_max - 1] = '\0';
|
||||
return QString::fromLocal8Bit(gethostbuffer);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue