diff -r c0042fa5433b -r 7b722739e329 me8100_test_dio/rtest.c --- a/me8100_test_dio/rtest.c Thu Jan 24 18:53:47 2002 +0100 +++ b/me8100_test_dio/rtest.c Fri Jan 25 16:55:00 2002 +0100 @@ -20,27 +20,27 @@ #include #include #include - +#include #include "me8100.h" #define USE_READ -int main(void){ - int err = 0; - static int file_handle = -1; +const char* DEVICE = "/dev/me8100_0a"; +int main(int argc, char** argv) { + static int file_handle; unsigned short value_a; - printf("Read test, PID: %d\n", getpid()); + if (argc > 1) DEVICE = argv[1]; + + printf("Read test, from %s, PID: %d\n", DEVICE, getpid()); #ifdef USE_READ printf("Using read()\n"); #endif - /* file_handle = open("/dev/me8100_0a", O_RDONLY | O_NDELAY, 0); */ - file_handle = open("/dev/me8100_0a", O_RDONLY, 0); - if(file_handle < 0){ - printf("Cannot open path !\n"); - return 1; + if (-1 == (file_handle = open(DEVICE, O_RDONLY, 0))) { + fprintf(stderr, "Can't open %s: %m\n", DEVICE); + exit(EXIT_FAILURE); } for (;;sleep(1)) { @@ -61,10 +61,9 @@ printf("Read %04x\n", value_a); } - err = close(file_handle); - if(err){ - printf("Kann Pfad nicht schliessen\n"); - return 1; + if(0 != close(file_handle)) { + perror("Can't close device"); + exit(EXIT_FAILURE); } return 0;