'시스템프로그래밍'에 해당되는 글 1건
- 2007/04/24 uid로 username찾기.
gid로 그룹명 따오는거 까진 문제가 없었는데 uid로 유저명을 찾아오는데서 막혀버렸다.
결국 ls 소스를 뒤져서 답을 찾았다.
char *
getuser (uid_t uid)
{
struct userid *tail;
struct userid *match = NULL;
for (tail = user_alist; tail; tail = tail->next)
{
if (tail->id.u == uid)
{
match = tail;
break;
}
}
if (match == NULL)
{
struct passwd *pwent = getpwuid (uid);
char const *name = pwent ? pwent->pw_name : "";
match = xmalloc (offsetof (struct userid, name) + strlen (name) + 1);
match->id.u = uid;
strcpy (match->name, name);
/* Add to the head of the list, so most recently used is first. */
match->next = user_alist;
user_alist = match;
}
return match->name[0] ? match->name : NULL;
}
내가 네트웍 프로그래밍을 듣는 건지 시스템 프로그래밍을 듣는 건지.
점점 뻘짓으로 빠져가는 듯 하다.
'Programming' 카테고리의 다른 글
| SWT 어플리케이션에서 구글맵 활용 (0) | 2008/07/22 |
|---|---|
| 07년 프로그래밍 언어 중간 평가 2 (0) | 2007/05/06 |
| 프로그래밍 언어 06년 기말고사 (4) | 2007/05/04 |
| 프로그래밍 언어 06년 중간시험 2 (2) | 2007/05/03 |
| uid로 username찾기. (0) | 2007/04/24 |

Prev
Rss Feed