From c3fc72deb32e0928593f000fdc7550bbbdcdd9a6 Mon Sep 17 00:00:00 2001 From: George Fox Date: Tue, 7 Nov 2023 18:52:01 +0300 Subject: [PATCH 1/2] Some changes that I think makes it better --- builder/builder.c | 14 +++----------- builder/config.h | 2 +- coreutils/echo.c | 3 ++- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/builder/builder.c b/builder/builder.c index 34010c7..f1a2080 100644 --- a/builder/builder.c +++ b/builder/builder.c @@ -35,18 +35,10 @@ void Compile(const char *src, const char *output_dir) { char *path = MakePath(src, output_dir); printf("[CC] Building %s -> %s\n", src, path); - size_t len = strlen(CC) + strlen(CFLAGS) + strlen(src) + strlen(path) + 7; - char *arg = malloc(len + 1); - if (arg == NULL) { - free(path); - fprintf(stderr, "builder: malloc failed"); - exit(1); + if (fork()) { + execlp(CC, CC, CFLAGS, src, "-o", path, NULL); } - - snprintf(arg, len, "%s %s %s -o %s", CC, CFLAGS, src, path); - system(arg); - - free(arg); + free(path); } diff --git a/builder/config.h b/builder/config.h index 0274fa1..e47e89d 100644 --- a/builder/config.h +++ b/builder/config.h @@ -14,6 +14,6 @@ const char *libs[] = { "readline" }; -#define CFLAGS "-Wall -Wextra -pedantic -Os -s -I ../libmu" +#define CFLAGS "-Wall", "-Wextra", "-pedantic", "-Os", "-s", "-I", "../libmu" #define CC "cc" #endif diff --git a/coreutils/echo.c b/coreutils/echo.c index e4fe93a..9146b2b 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c @@ -8,7 +8,8 @@ int main(const int argc, const char **argv) { putchar(' '); } } - + // https://pubs.opengroup.org/onlinepubs/009604599/utilities/echo.html + // This version does not support -n option and escape-sequences putchar('\n'); return 0; } From 3afc38f7e7e9e0461c67064147973b1e1b812c58 Mon Sep 17 00:00:00 2001 From: George Fox Date: Tue, 7 Nov 2023 18:52:38 +0300 Subject: [PATCH 2/2] Woops, forgot to add this one. --- coreutils/cat.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/coreutils/cat.c b/coreutils/cat.c index 8ecda05..d3e3c97 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c @@ -14,13 +14,16 @@ void cat(const int fd) { } int main(const int argc, const char **argv) { - if (argc == 1 || argv[1][0] == '-') + if (argc == 1) cat(STDIN_FILENO); else { for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') - break; + if (argv[i][1]) + break; + else + cat(STDIN_FILENO); int fd = open(argv[i], O_RDONLY); if (fd < 0) {