🦄 refactor(C13, C14, C115): 更新了linux系统开发部分的结构
This commit is contained in:
29
C14-文件系统/username.c
Normal file
29
C14-文件系统/username.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* @brief 用user id获取用户名
|
||||
* @details
|
||||
*
|
||||
* @param argc
|
||||
* @param argv
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <user id>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct passwd *pwdline;
|
||||
|
||||
pwdline = getpwuid(atoi(argv[1]));
|
||||
|
||||
puts(pwdline->pw_name);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user