Added dumb group functions - they only know one group: "users" (should be pretty similar to R5).

Implemented and added functions from inttypes.h (not everything is working correctly, though).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8787 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-09-02 01:03:01 +00:00
parent 929525b836
commit 39536410a6
3 changed files with 172 additions and 0 deletions

View File

@ -8,6 +8,8 @@ KernelMergeObject posix_main.o :
errno.c
fnmatch.c
glob.c
grp.c
inttypes.c
poll.c
pwd.c
syslog.cpp

View File

@ -0,0 +1,121 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
/* Dumb group functions - only know the "users" group with group ID 0 right
* now - this should definitely be thought over :-)
*/
#include <SupportDefs.h>
#include <grp.h>
#include <string.h>
static int32 sGroupIndex;
static struct group sGroup;
static void
get_users(struct group *gr)
{
static char *nothing = "";
gr->gr_name = "users";
gr->gr_passwd = NULL;
gr->gr_gid = 0;
gr->gr_mem = &nothing;
}
static void
init_users()
{
if (sGroupIndex == 0) {
// initial construction of the group
get_users(&sGroup);
sGroupIndex = 1;
}
}
struct group *
getgrgid(gid_t gid)
{
if (gid != 0)
return NULL;
init_users();
return &sGroup;
}
int
getgrgid_r(gid_t gid, struct group *group, char *buffer,
size_t bufferSize, struct group **_result)
{
if (gid != 0) {
*_result = NULL;
return B_ENTRY_NOT_FOUND;
}
get_users(group);
*_result = group;
return B_OK;
}
struct group *
getgrnam(const char *name)
{
if (strcmp("users", name))
return NULL;
init_users();
return &sGroup;
}
int
getgrnam_r(const char *name, struct group *group, char *buffer,
size_t bufferSize, struct group **_result)
{
if (strcmp("users", name)) {
*_result = NULL;
return B_ENTRY_NOT_FOUND;
}
get_users(group);
*_result = group;
return B_OK;
}
struct group *
getgrent(void)
{
if (sGroupIndex > 1)
return NULL;
init_users();
sGroupIndex++;
return &sGroup;
}
void
setgrent(void)
{
init_users();
}
void
endgrent(void)
{
init_users();
}

View File

@ -0,0 +1,49 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <inttypes.h>
#include <stdlib.h>
intmax_t
imaxabs(intmax_t number)
{
return number > 0 ? number : -number;
}
imaxdiv_t
imaxdiv(intmax_t numer, intmax_t denom)
{
imaxdiv_t result;
result.quot = numer / denom;
result.rem = numer % denom;
if (numer >= 0 && result.rem < 0) {
result.quot++;
result.rem -= denom;
}
return result;
}
intmax_t
strtoimax(const char *string, char **_end, int base)
{
// ToDo: implement me properly!
return (intmax_t)strtol(string, _end, base);
}
uintmax_t
strtoumax(const char *string, char **_end, int base)
{
// ToDo: implement me properly!
return (intmax_t)strtoul(string, _end, base);
}