ask_confirmation.c 713 B

12345678910111213141516171819202122232425262728293031323334
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * bb_ask_confirmation 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 tarball for details.
  8. */
  9. /* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y',
  10. * return 1. Otherwise return 0.
  11. */
  12. #include "libbb.h"
  13. int bb_ask_confirmation(void)
  14. {
  15. int retval = 0;
  16. int first = 1;
  17. int c;
  18. while (((c = getchar()) != EOF) && (c != '\n')) {
  19. /* Make sure we get the actual function call for isspace,
  20. * as speed is not critical here. */
  21. if (first && !(isspace)(c)) {
  22. --first;
  23. if ((c == 'y') || (c == 'Y')) {
  24. ++retval;
  25. }
  26. }
  27. }
  28. return retval;
  29. }