diff --git a/builder/config.h b/builder/config.h index 6ea443d..892e4df 100644 --- a/builder/config.h +++ b/builder/config.h @@ -10,6 +10,6 @@ const char *objects[] = { /* "sysutils" */ }; -#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I", "../libmu" +#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I", "../libmu", "-I", "../" #define CC "cc" #endif diff --git a/config.h b/config.h new file mode 100644 index 0000000..f67bf55 --- /dev/null +++ b/config.h @@ -0,0 +1,14 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +/* Depends: cat tee wc */ +#define BUF_SIZE 4096 + +/* Random source for shred */ +#define RAND_SOURCE "/dev/urandom" + +/* Options. To disable, comment line */ +/* Add escape-char support in echo */ +#define ECHO_FANCY + +#endif diff --git a/coreutils/cat.c b/coreutils/cat.c index f18dca2..ace88a7 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c @@ -3,9 +3,10 @@ #include #include #include +#include "config.h" void cat(const int fd) { - char buf[4096]; + char buf[BUF_SIZE + 1]; ssize_t len; while ((len = read(fd, buf, sizeof(buf))) > 0) diff --git a/coreutils/dirname.c b/coreutils/dirname.c index ecb58f1..0b2f7e6 100644 --- a/coreutils/dirname.c +++ b/coreutils/dirname.c @@ -2,7 +2,6 @@ #include int main(const int argc, char **argv) { - if (argc <= 1) { printf("dirname [dirname]\n"); return 1; diff --git a/coreutils/echo.c b/coreutils/echo.c index 1d3eaef..e067ef9 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c @@ -1,8 +1,10 @@ #include #include #include +#include "config.h" void format(char *str) { +#ifdef ECHO_FANCY for (size_t i = 0; i < strlen(str); i++) { unsigned int c = str[i]; if (c == '\\') { @@ -51,6 +53,11 @@ void format(char *str) { putchar(c); } + +#else + fputs(str, stdout); + +#endif } int main(int argc, char **argv) { diff --git a/coreutils/ln.c b/coreutils/ln.c index 0cedf81..154bfc5 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c @@ -20,7 +20,6 @@ int ln(const char *src, const char *dst) { } int main(int argc, char **argv) { - int opt; while ((opt = getopt(argc, argv, "sf")) != -1) { switch (opt) { diff --git a/coreutils/shred.c b/coreutils/shred.c index 82f8406..235b402 100644 --- a/coreutils/shred.c +++ b/coreutils/shred.c @@ -6,8 +6,7 @@ #include #include #include - -#define RAND_SOURCE "/dev/urandom" +#include "config.h" unsigned int f_flag; unsigned int u_flag; diff --git a/coreutils/tee.c b/coreutils/tee.c index 3e67af9..c9c10c4 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c @@ -3,6 +3,7 @@ #include #include #include +#include "config.h" int main(int argc, char **argv) { int flag = O_TRUNC; @@ -38,11 +39,11 @@ int main(int argc, char **argv) { } - char in[4096]; + char buf[BUF_SIZE + 1]; off_t bytes = 0; - while ((bytes = read(STDIN_FILENO, in, sizeof(in)))) { - write(STDOUT_FILENO, in, bytes); - write(fd, in, bytes); + while ((bytes = read(STDIN_FILENO, buf, sizeof(buf)))) { + write(STDOUT_FILENO, buf, bytes); + write(fd, buf, bytes); } close(fd); diff --git a/coreutils/wc.c b/coreutils/wc.c index 83ab93a..02d9caf 100644 --- a/coreutils/wc.c +++ b/coreutils/wc.c @@ -4,6 +4,7 @@ #include #include #include +#include "config.h" /* cmd arguments l - lines c - bytes w - words */ unsigned int l_flag; @@ -20,7 +21,7 @@ unsigned int tbytes; unsigned int tlines; void count(const int fd) { - char buf[4096]; + char buf[BUF_SIZE + 1]; off_t n = 0; int in_word = 1; diff --git a/coreutils/whoami.c b/coreutils/whoami.c index f8880d5..0bee9cb 100644 --- a/coreutils/whoami.c +++ b/coreutils/whoami.c @@ -1,7 +1,6 @@ #include #include #include - #include #include #include