diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-09 19:20:15 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-09 19:20:15 +0100 |
| commit | 885f5974cdf65b59415837ae97f5a14ef1350670 (patch) | |
| tree | 66ac13de29c7f4932c5fcae11773df574e4e256a /bin/echo | |
| parent | 8f9e448b2ef6db7cd905540c21f3c5b190e7a1e7 (diff) | |
feat: add gzip and new headers
Diffstat (limited to 'bin/echo')
| -rw-r--r-- | bin/echo/Kbuild | 5 | ||||
| -rwxr-xr-x | bin/echo/echo | bin | 0 -> 3480 bytes | |||
| -rw-r--r-- | bin/echo/echo.c | 30 |
3 files changed, 35 insertions, 0 deletions
diff --git a/bin/echo/Kbuild b/bin/echo/Kbuild new file mode 100644 index 00000000..919423fd --- /dev/null +++ b/bin/echo/Kbuild @@ -0,0 +1,5 @@ +bin-y := echo + +libs-y += $(srctree)/lib/libc/libc.a + +obj-y += echo.o diff --git a/bin/echo/echo b/bin/echo/echo Binary files differnew file mode 100755 index 00000000..c9bbb0df --- /dev/null +++ b/bin/echo/echo diff --git a/bin/echo/echo.c b/bin/echo/echo.c new file mode 100644 index 00000000..b8e5bbe0 --- /dev/null +++ b/bin/echo/echo.c @@ -0,0 +1,30 @@ +#include <string.h> +#include <unistd.h> +#include <sys/uio.h> + +int main(int argc, char **argv) +{ + if (argc <= 1) + return 0; + + struct iovec iov[2 * argc - 2]; + int iovcnt = 0; + + for (int i = 1; i < argc; i++) { + iov[iovcnt].iov_base = argv[i]; + iov[iovcnt].iov_len = strlen(argv[i]); + iovcnt++; + + if (i < argc - 1) { + iov[iovcnt].iov_base = " "; + iov[iovcnt].iov_len = 1; + iovcnt++; + } + } + + iov[iovcnt].iov_base = "\n"; + iov[iovcnt].iov_len = 1; + iovcnt++; + + return writev(STDOUT_FILENO, iov, iovcnt) < 0 ? 1 : 0; +} |
