问题描述
如何检索当前登录用户的用户名?我基本上要检查用户是否以root身份登录,如果没有,请退出
程序。
我虽然关于使用LOGNAME环境变量,但如果普通的
用户使用su root,则环境变量仍然具有用户的登录名
名称。
How do I retrieve the username of the currently logged in user? I
basically to check if the user is logged in as root and if not, exit
the program.
I though about using the LOGNAME environment variable, but if a regular
user used su root, the environment variable still has the user''s login
name.
推荐答案
这不是C问题,试试comp .unix.programmer。
Robert Gamble
This is not a C question, try comp.unix.programmer.
Robert Gamble
C中没有标准方法。最好的办法是询问与您选择的平台相关的
a新闻组,
,如comp.unix.programmer。
< OT>如果您可以假设POSIX,请查看是否
getpwuid和getuid做你想做的事。但
对它们的讨论应该在
comp.unix.programmer< / OT>
-David
There is no standard way in C. Your best bet is to ask in
a newsgroup(s) associated with your platform(s) of choice,
such as comp.unix.programmer.
<OT> If you can assume POSIX, look at whether
getpwuid and getuid do what you want. But
discussion on them should be in
comp.unix.programmer </OT>
-David
这篇关于获取当前用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!