#include "current_user_helper.h"

#include <QProcessEnvironment>

#include <pwd.h>
#include <unistd.h>

QString CurrentUserHelper::currentUsername() {
    const QString envUser = QProcessEnvironment::systemEnvironment().value(QStringLiteral("USER"));
    if (!envUser.isEmpty()) return envUser;

    struct passwd* pw = getpwuid(geteuid());
    if (pw && pw->pw_name) {
        return QString::fromLocal8Bit(pw->pw_name);
    }

    return QString();
}
