GMS Linux: start?

This commit is contained in:
2025-12-30 01:20:20 +00:00
commit ac241a9148
48 changed files with 2028 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
TARGET = cat
SRCS = cat.c
CC = gcc
CFLAGS = -static -Wall
OUT_BIN ?= $(TARGET)
all: $(OUT_BIN)
$(OUT_BIN): $(SRCS)
@echo " [CC] Compiling to $(OUT_BIN)..."
$(CC) $(CFLAGS) -o $@ $^
clean:
rm -f $(TARGET)
+30
View File
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char buf[1024];
int n;
int fd;
if (argc == 1) {
while ((n = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
write(STDOUT_FILENO, buf, n);
}
return 0;
}
for (int i = 1; i < argc; i++) {
fd = open(argv[i], O_RDONLY);
if (fd < 0) {
perror(argv[i]);
continue;
}
while ((n = read(fd, buf, sizeof(buf))) > 0) {
write(STDOUT_FILENO, buf, n);
}
close(fd);
}
return 0;
}