From 38196dea30d290e436033ccbe0f7f08cd7d862a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Fri, 11 Jan 2008 13:47:45 +0000 Subject: [PATCH] Move getlogin*() to its own file and fix the build. This way it doesn't get linked to the kernel. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23395 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/pwd.c | 24 -------------- src/system/libroot/posix/pwd_query.c | 24 -------------- src/system/libroot/posix/unistd/Jamfile | 1 + src/system/libroot/posix/unistd/getlogin.c | 38 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 48 deletions(-) create mode 100644 src/system/libroot/posix/unistd/getlogin.c diff --git a/src/system/libroot/posix/pwd.c b/src/system/libroot/posix/pwd.c index 404831463f..ce6d351b76 100644 --- a/src/system/libroot/posix/pwd.c +++ b/src/system/libroot/posix/pwd.c @@ -133,27 +133,3 @@ getpwuid_r(uid_t uid, struct passwd *passwd, char *buffer, return 0; } - -char *getlogin() -{ - struct passwd *pw; - pw = getpwuid(getuid()); - if (pw) - return pw->pw_name; - errno = ENOMEM; - return NULL; -} - - -int getlogin_r(char *name, size_t nameSize) -{ - struct passwd *pw; - pw = getpwuid(getuid()); - if (pw && (nameSize > 32/*PW_MAX_NAME*/)) { - memset(name, 0, nameSize); - strlcpy(name, pw->pw_name, 32/*PW_MAX_NAME*/); - return B_OK; - } - return ENOMEM; -} - diff --git a/src/system/libroot/posix/pwd_query.c b/src/system/libroot/posix/pwd_query.c index 521df6aa03..65e6f7a695 100644 --- a/src/system/libroot/posix/pwd_query.c +++ b/src/system/libroot/posix/pwd_query.c @@ -621,30 +621,6 @@ struct passwd *getpwnam(const char *name) } -char *getlogin() -{ - struct passwd *pw; - pw = getpwuid(getuid()); - if (pw) - return pw->pw_name; - errno = ENOMEM; - return NULL; -} - - -int getlogin_r(char *name, size_t nameSize) -{ - struct passwd *pw; - pw = getpwuid(getuid()); - if (pw && (nameSize > 32/*PW_MAX_NAME*/)) { - memset(name, 0, nameSize); - strlcpy(name, pw->pw_name, 32/*PW_MAX_NAME*/); - return B_OK; - } - return ENOMEM; -} - - void __init_pwd_stuff(void) //void _multiuser_init(void) { diff --git a/src/system/libroot/posix/unistd/Jamfile b/src/system/libroot/posix/unistd/Jamfile index 54ea8dc0b0..cb74474b4a 100644 --- a/src/system/libroot/posix/unistd/Jamfile +++ b/src/system/libroot/posix/unistd/Jamfile @@ -14,6 +14,7 @@ MergeObject posix_unistd.o : _exit.c fcntl.c fork.c + getlogin.c hostname.cpp ioctl.c link.c diff --git a/src/system/libroot/posix/unistd/getlogin.c b/src/system/libroot/posix/unistd/getlogin.c new file mode 100644 index 0000000000..3a6b41049e --- /dev/null +++ b/src/system/libroot/posix/unistd/getlogin.c @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include +#include +#include +#include + + +char *getlogin() +{ + struct passwd *pw; + pw = getpwuid(getuid()); + if (pw) + return pw->pw_name; + errno = ENOMEM; + return NULL; +} + + +int getlogin_r(char *name, size_t nameSize) +{ + struct passwd *pw; + pw = getpwuid(getuid()); + if (pw && (nameSize > 32/*PW_MAX_NAME*/)) { + memset(name, 0, nameSize); + strlcpy(name, pw->pw_name, 32/*PW_MAX_NAME*/); + return B_OK; + } + return ENOMEM; +} +