vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / unistd / getlogin.c
blob9d809de4dbe53d2281b2ff50fbee2e2752021ba5
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 */
7 #include <syscalls.h>
9 #include <errno.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <pwd.h>
15 #include <errno_private.h>
18 char *getlogin()
20 struct passwd *pw;
21 pw = getpwuid(getuid());
22 if (pw)
23 return pw->pw_name;
24 __set_errno(ENOMEM);
25 return NULL;
29 int getlogin_r(char *name, size_t nameSize)
31 struct passwd *pw;
32 pw = getpwuid(getuid());
33 if (pw && (nameSize >= LOGIN_NAME_MAX)) {
34 memset(name, 0, nameSize);
35 strlcpy(name, pw->pw_name, LOGIN_NAME_MAX);
36 return B_OK;
38 return ENOMEM;
42 char *
43 cuserid(char *s)
45 if (s != NULL && getlogin_r(s, L_cuserid))
46 return s;
48 return getlogin();