1/*
2 * Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <syscalls.h>
8
9#include <errno.h>
10#include <stdio.h>
11#include <string.h>
12#include <unistd.h>
13#include <pwd.h>
14
15#include <errno_private.h>
16
17
18char *getlogin()
19{
20	struct passwd *pw;
21	pw = getpwuid(getuid());
22	if (pw)
23		return pw->pw_name;
24	__set_errno(ENOMEM);
25	return NULL;
26}
27
28
29int getlogin_r(char *name, size_t nameSize)
30{
31	struct passwd *pw;
32	pw = getpwuid(getuid());
33	if (pw && (nameSize > 32/*PW_MAX_NAME*/)) {
34		memset(name, 0, nameSize);
35		strlcpy(name, pw->pw_name, 32/*PW_MAX_NAME*/);
36		return B_OK;
37	}
38	return ENOMEM;
39}
40
41
42char *
43cuserid(char *s)
44{
45	if (s != NULL && getlogin_r(s, L_cuserid))
46		return s;
47
48	return getlogin();
49}
50
51