On Thu, Nov 28, 2019 at 1:46 PM Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> wrote: [...] > + auto lamRootHome = [] () { > + QFile fPswd("/etc/passwd"); > + QString home("/root"); > + QStringList userInfo; > + > + fPswd.open(QIODevice::ReadOnly); > + if (!fPswd.isOpen()) > + return home; > + > + QTextStream s(&fPswd); > + while (!s.atEnd()) { > + userInfo = s.readLine().split(':'); > + > + /* Check the User Id. */ > + if (userInfo[2].toInt() == 0) { > + home = userInfo[5]; > + break; > + } > + } > + Another option is to use getpwent(3) [0] instead of parsing /etc/passwd by hand. Cheers, -- Slavi [0] http://man7.org/linux/man-pages/man3/getpwent.3.html
![]() |