ask_confirmation.c 561 B

123456789101112131415161718192021222324252627
  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 source tree.
  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 FAST_FUNC bb_ask_confirmation(void)
  14. {
  15. char first = 0;
  16. int c;
  17. while (((c = getchar()) != EOF) && (c != '\n')) {
  18. if (first == 0 && !isblank(c)) {
  19. first = c|0x20;
  20. }
  21. }
  22. return first == 'y';
  23. }