"Fossies" - the Fresh Open Source Software Archive

Member "i2c-tools-4.3/tools/util.c" (22 Jul 2021, 1314 Bytes) of package /linux/misc/i2c-tools-4.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "util.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2     util.c - helper functions
    3     Copyright (C) 2006-2009  Jean Delvare <jdelvare@suse.de>
    4 
    5     This program is free software; you can redistribute it and/or modify
    6     it under the terms of the GNU General Public License as published by
    7     the Free Software Foundation; either version 2 of the License, or
    8     (at your option) any later version.
    9 
   10     This program is distributed in the hope that it will be useful,
   11     but WITHOUT ANY WARRANTY; without even the implied warranty of
   12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13     GNU General Public License for more details.
   14 
   15     You should have received a copy of the GNU General Public License
   16     along with this program; if not, write to the Free Software
   17     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   18     MA 02110-1301 USA.
   19 */
   20 
   21 #include <stdio.h>
   22 #include "util.h"
   23 
   24 /* Return 1 if we should continue, 0 if we should abort */
   25 int user_ack(int def)
   26 {
   27     char s[2];
   28     int ret;
   29 
   30     if (!fgets(s, 2, stdin))
   31         return 0; /* Nack by default */
   32 
   33     switch (s[0]) {
   34     case 'y':
   35     case 'Y':
   36         ret = 1;
   37         break;
   38     case 'n':
   39     case 'N':
   40         ret = 0;
   41         break;
   42     default:
   43         ret = def;
   44     }
   45 
   46     /* Flush extra characters */
   47     while (s[0] != '\n') {
   48         int c = fgetc(stdin);
   49         if (c == EOF) {
   50             ret = 0;
   51             break;
   52         }
   53         s[0] = c;
   54     }
   55 
   56     return ret;
   57 }
   58