GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/top/username.c Lines: 0 4 0.0 %
Date: 2017-11-07 Branches: 0 2 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: username.c,v 1.17 2015/10/26 13:56:18 tedu Exp $	 */
2
3
/*
4
 *  Top users/processes display for Unix
5
 *  Version 3
6
 *
7
 * Copyright (c) 1984, 1989, William LeFebvre, Rice University
8
 * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions
12
 * are met:
13
 * 1. Redistributions of source code must retain the above copyright
14
 *    notice, this list of conditions and the following disclaimer.
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in the
17
 *    documentation and/or other materials provided with the distribution.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE AUTHOR OR HIS EMPLOYER BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
/*
32
 *  Username translation code for top.
33
 */
34
35
#include <sys/types.h>
36
#include <stdio.h>
37
#include <string.h>
38
#include <pwd.h>
39
40
#include "top.local.h"
41
#include "top.h"
42
#include "utils.h"
43
44
char *
45
username(uid_t uid)
46
{
47
	return user_from_uid(uid, 0);
48
}
49
50
uid_t
51
userid(char *username)
52
{
53
	struct passwd *pwd;
54
55
	if ((pwd = getpwnam(username)) == NULL)
56
		return ((uid_t)-1);
57
58
	return (pwd->pw_uid);
59
}