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/echo.c | |
| parent | 8f9e448b2ef6db7cd905540c21f3c5b190e7a1e7 (diff) | |
feat: add gzip and new headers
Diffstat (limited to 'bin/echo/echo.c')
| -rw-r--r-- | bin/echo/echo.c | 30 |
1 files changed, 30 insertions, 0 deletions
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; +} |
