1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:17:35 +00:00

Add sys$gethostname and /bin/hostname

This commit is contained in:
Andreas Kling 2018-10-26 09:54:29 +02:00
parent 3faaa3e04a
commit 53abfa7ea1
16 changed files with 77 additions and 40 deletions

1
Userland/.gitignore vendored
View file

@ -7,4 +7,5 @@ sleep
date
false
true
hostname
*.o

View file

@ -7,7 +7,8 @@ OBJS = \
sleep.o \
date.o \
true.o \
false.o
false.o \
hostname.o
APPS = \
id \
@ -18,7 +19,8 @@ APPS = \
sleep \
date \
true \
false
false \
hostname
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
@ -65,6 +67,9 @@ true: true.o
false: false.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
hostname: hostname.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<

17
Userland/hostname.cpp Normal file
View file

@ -0,0 +1,17 @@
#include <LibC/unistd.h>
#include <LibC/stdio.h>
#include <LibC/errno.h>
#include <LibC/string.h>
int main(int c, char** v)
{
char buffer[HOST_NAME_MAX];
int rc = gethostname(buffer, sizeof(buffer));
if (rc < 0) {
printf("gethostname() error: %s\n", strerror(errno));
return 1;
}
printf("%s\n", buffer);
return 0;
}