GMS Linux: start?
This commit is contained in:
@@ -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)
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user