mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 14:37:45 +00:00
Add getpwent() family of functions to LibC.
Also add a little /etc/passwd database. There's just me in there.
This commit is contained in:
parent
819ce91395
commit
9886b27d9c
17 changed files with 175 additions and 25 deletions
|
@ -3,7 +3,6 @@ OBJS = \
|
|||
sh.o \
|
||||
ps.o \
|
||||
ls.o \
|
||||
pwd.o \
|
||||
sleep.o \
|
||||
date.o \
|
||||
true.o \
|
||||
|
@ -21,7 +20,6 @@ APPS = \
|
|||
sh \
|
||||
ps \
|
||||
ls \
|
||||
pwd \
|
||||
sleep \
|
||||
date \
|
||||
true \
|
||||
|
@ -64,9 +62,6 @@ ps: ps.o
|
|||
ls: ls.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
pwd: pwd.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
sleep: sleep.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
#include <LibC/unistd.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/pwd.h>
|
||||
|
||||
int main(int c, char** v)
|
||||
{
|
||||
uid_t uid = getuid();
|
||||
gid_t gid = getgid();
|
||||
pid_t pid = getpid();
|
||||
printf("uid=%u, gid=%u, pid=%u\n", uid, gid, pid);
|
||||
|
||||
struct passwd* pw = getpwuid(uid);
|
||||
|
||||
printf("uid=%u(%s), gid=%u\n", uid, pw ? pw->pw_name : "n/a", gid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
#include <LibC/unistd.h>
|
||||
#include <LibC/stdio.h>
|
||||
|
||||
int main(int c, char** v)
|
||||
{
|
||||
char buffer[1024];
|
||||
char* ptr = getcwd(buffer, sizeof(buffer));
|
||||
if (!ptr) {
|
||||
printf("getcwd() failed\n");
|
||||
return 1;
|
||||
}
|
||||
printf("%s\n", ptr);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue