3
0

ask_confirmation.c 751 B

123456789101112131415161718192021222324252627282930313233343536
  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 <stdio.h>
  13. #include <ctype.h>
  14. #include "libbb.h"
  15. int bb_ask_confirmation(void)
  16. {
  17. int retval = 0;
  18. int first = 1;
  19. int c;
  20. while (((c = getchar()) != EOF) && (c != '\n')) {
  21. /* Make sure we get the actual function call for isspace,
  22. * as speed is not critical here. */
  23. if (first && !(isspace)(c)) {
  24. --first;
  25. if ((c == 'y') || (c == 'Y')) {
  26. ++retval;
  27. }
  28. }
  29. }
  30. return retval;
  31. }