~mmach/netext73/lm-sensors

« back to all changes in this revision

Viewing changes to prog/dump/util.c

  • Committer: mmach
  • Date: 2020-02-05 20:28:34 UTC
  • Revision ID: netbit73@gmail.com-20200205202834-zc3sla47j9e700w5
3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    util.c - helper functions
 
3
    Copyright (C) 2006-2011 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
 
 
11
#include <sys/io.h>
 
12
#include <stdio.h>
 
13
#include "util.h"
 
14
 
 
15
/* Return 1 if we should continue, 0 if we should abort */
 
16
int user_ack(int def)
 
17
{
 
18
        char s[2];
 
19
        int ret;
 
20
 
 
21
        if (!fgets(s, 2, stdin))
 
22
                return 0; /* Nack by default */
 
23
 
 
24
        switch (s[0]) {
 
25
        case 'y':
 
26
        case 'Y':
 
27
                ret = 1;
 
28
                break;
 
29
        case 'n':
 
30
        case 'N':
 
31
                ret = 0;
 
32
                break;
 
33
        default:
 
34
                ret = def;
 
35
        }
 
36
 
 
37
        /* Flush extra characters */
 
38
        while (s[0] != '\n') {
 
39
                int c = fgetc(stdin);
 
40
                if (c == EOF) {
 
41
                        ret = 0;
 
42
                        break;
 
43
                }
 
44
                s[0] = c;
 
45
        }
 
46
 
 
47
        return ret;
 
48
}
 
49
 
 
50
/* I/O read of specified size */
 
51
unsigned long inx(int addr, int width)
 
52
{
 
53
        switch (width) {
 
54
        case 2:
 
55
                return inw(addr);
 
56
                break;
 
57
        case 4:
 
58
                return inl(addr);
 
59
                break;
 
60
        default:
 
61
                return inb(addr);
 
62
        }
 
63
}
 
64
 
 
65
/* I/O write of specified size */
 
66
void outx(unsigned long value, int addr, int width)
 
67
{
 
68
        switch (width) {
 
69
        case 2:
 
70
                outw(value, addr);
 
71
                break;
 
72
        case 4:
 
73
                outl(value, addr);
 
74
                break;
 
75
        default:
 
76
                outb(value, addr);
 
77
        }
 
78
}