diff --git a/src/kernel/libroot/posix/Jamfile b/src/kernel/libroot/posix/Jamfile index 8bb51eb6e1..443f9aa2b4 100644 --- a/src/kernel/libroot/posix/Jamfile +++ b/src/kernel/libroot/posix/Jamfile @@ -8,6 +8,8 @@ KernelMergeObject posix_main.o : errno.c fnmatch.c glob.c + grp.c + inttypes.c poll.c pwd.c syslog.cpp diff --git a/src/kernel/libroot/posix/grp.c b/src/kernel/libroot/posix/grp.c new file mode 100644 index 0000000000..025a7c0bbf --- /dev/null +++ b/src/kernel/libroot/posix/grp.c @@ -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 + +#include +#include + + +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 = ¬hing; +} + + +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(); +} + diff --git a/src/kernel/libroot/posix/inttypes.c b/src/kernel/libroot/posix/inttypes.c new file mode 100644 index 0000000000..711c02f7a6 --- /dev/null +++ b/src/kernel/libroot/posix/inttypes.c @@ -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 +#include + + +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); +} +