File indexing completed on 2024-03-24 04:02:31

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
0003     SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #ifndef SYSTEMINFORMATION_P_H
0008 #define SYSTEMINFORMATION_P_H
0009 
0010 #include <QString>
0011 
0012 namespace SystemInformation
0013 {
0014 QString userName();
0015 }
0016 
0017 #if !defined(Q_OS_WIN)
0018 #include <pwd.h>
0019 #include <sys/utsname.h>
0020 #include <unistd.h>
0021 inline QString SystemInformation::userName()
0022 {
0023     struct passwd *p = getpwuid(getuid());
0024     return QString::fromLatin1(p->pw_name);
0025 }
0026 
0027 #else
0028 #include <QOperatingSystemVersion>
0029 #include <qt_windows.h>
0030 #define SECURITY_WIN32
0031 #include <security.h>
0032 //#include <secext.h> // GetUserNameEx
0033 
0034 inline QString SystemInformation::userName()
0035 {
0036     WCHAR nameBuffer[256];
0037     DWORD bufsize = 256;
0038     if (!GetUserNameExW(NameDisplay, nameBuffer, &bufsize)) {
0039         return QStringLiteral("Unknown User"); // should never happen (translate?)
0040     }
0041     return QString::fromWCharArray(nameBuffer);
0042 }
0043 
0044 #endif
0045 
0046 #endif // SYSTEMINFORMATION_P_H