1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
3 SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#ifndef SYSTEMINFORMATION_P_H
8#define SYSTEMINFORMATION_P_H
9
10#include <QString>
11
12namespace SystemInformation
13{
14QString userName();
15}
16
17#if !defined(Q_OS_WIN)
18#include <pwd.h>
19#include <sys/utsname.h>
20#include <unistd.h>
21inline QString SystemInformation::userName()
22{
23 struct passwd *p = getpwuid(uid: getuid());
24 return QString::fromLatin1(ba: p->pw_name);
25}
26
27#else
28#include <QOperatingSystemVersion>
29#include <qt_windows.h>
30#define SECURITY_WIN32
31#include <security.h>
32//#include <secext.h> // GetUserNameEx
33
34inline QString SystemInformation::userName()
35{
36 WCHAR nameBuffer[256];
37 DWORD bufsize = 256;
38 if (!GetUserNameExW(NameDisplay, nameBuffer, &bufsize)) {
39 return QStringLiteral("Unknown User"); // should never happen (translate?)
40 }
41 return QString::fromWCharArray(nameBuffer);
42}
43
44#endif
45
46#endif // SYSTEMINFORMATION_P_H
47

source code of kxmlgui/src/systeminformation_p.h