runit-logger.c 624 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * this program writes to stdout what it reads from stdin
  3. *
  4. * cc runit-logger.c -o runit-logger
  5. *
  6. * clang -std=c99 $(portageq envvar COMMON_FLAGS) $(portageq envvar LDFLAGS) \
  7. * runit-logger.c -o runit-logger
  8. */
  9. #define _POSIX_C_SOURCE 200809L
  10. #include <err.h>
  11. #include <errno.h>
  12. #include <stdio.h>
  13. #include <unistd.h>
  14. int
  15. main(void)
  16. {
  17. ssize_t readed;
  18. size_t len = 0;
  19. char *line = NULL;
  20. for (;;) {
  21. if ((readed = getline(&line, &len, stdin)) == -1) {
  22. if (!errno) return 0;
  23. warn("getline");
  24. continue;
  25. }
  26. if (write(STDOUT_FILENO, line, readed) != readed) warn("write");
  27. }
  28. return !0;
  29. }