3
0

ask_confirmation.c 675 B

1234567891011121314151617181920212223242526272829303132
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * bb_ask_y_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. #include "libbb.h"
  10. /* Read a line from fp. If the first non-whitespace char is 'y' or 'Y',
  11. * return 1. Otherwise return 0.
  12. */
  13. int FAST_FUNC bb_ask_y_confirmation_FILE(FILE *fp)
  14. {
  15. char first = 0;
  16. int c;
  17. fflush_all();
  18. while (((c = fgetc(fp)) != EOF) && (c != '\n')) {
  19. if (first == 0 && !isblank(c)) {
  20. first = c|0x20;
  21. }
  22. }
  23. return first == 'y';
  24. }
  25. int FAST_FUNC bb_ask_y_confirmation(void)
  26. {
  27. return bb_ask_y_confirmation_FILE(stdin);
  28. }