yes.c 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * yes implementation for busybox
  4. *
  5. * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
  10. /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
  11. *
  12. * Size reductions and removed redundant applet name prefix from error messages.
  13. */
  14. #include "libbb.h"
  15. /* This is a NOFORK applet. Be very careful! */
  16. //usage:#define yes_trivial_usage
  17. //usage: "[STRING]"
  18. //usage:#define yes_full_usage "\n\n"
  19. //usage: "Repeatedly output a line with STRING, or 'y'"
  20. int yes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  21. int yes_main(int argc UNUSED_PARAM, char **argv)
  22. {
  23. char **pp;
  24. argv[0] = (char*)"y";
  25. if (argv[1])
  26. ++argv;
  27. do {
  28. pp = argv;
  29. while (1) {
  30. fputs(*pp, stdout);
  31. if (!*++pp)
  32. break;
  33. putchar(' ');
  34. }
  35. } while (putchar('\n') != EOF);
  36. bb_perror_nomsg_and_die();
  37. }