2 * Copyright (C) 2016 Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
22 #define POST_DEFAULT_IO_PORT 0x80
24 void usage(char *progname
, const char *error
, ...)
26 printf("Usage: %s <VALUE> [PORT]\n", progname
);
27 printf("The VALUE argument is an integer between 0x00 and 0xff\n");
28 printf("The PORT argument is an integer between 0x00 and 0xffff\n");
33 va_start(args
, error
);
39 void check_int(long val
, int min
, int max
, int err
, char *string
, char *endptr
,
42 if (val
< min
|| val
> max
) {
44 "\nError: The value has to be between 0x%x and 0x%x\n",
49 if (endptr
== string
|| *endptr
!= '\0') {
50 usage(progname
, "\nError: An integer is required\n");
54 if ((err
) && (!val
)) {
60 int main(int argc
, char *argv
[])
63 unsigned long port
= POST_DEFAULT_IO_PORT
;
67 if (argc
!= 2 && argc
!= 3) {
72 val
= strtol(argv
[1], &endptr
, 0);
74 check_int(val
, 0x00, 0xff, err
, argv
[1], endptr
, argv
[0]);
77 port
= strtol(argv
[2], &endptr
, 0);
79 check_int(port
, 0x0000, 0xffff, err
, argv
[2], endptr
, argv
[0]);