Changeset 1053 for lm-sensors/trunk/prog/detect/i2cdetect.c
- Timestamp:
- 03/31/01 21:00:45 (11 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/prog/detect/i2cdetect.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/detect/i2cdetect.c
r847 r1053 2 2 i2cdetect.c - Part of i2cdetect, a user-space program to scan for I2C 3 3 devices. 4 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> 4 Copyright (c) 1999-2001 Frodo Looijaard <frodol@dds.nl> and 5 Mark D. Studebaker <mdsxyz123@yahoo.com> 5 6 6 7 This program is free software; you can redistribute it and/or modify … … 46 47 char *end; 47 48 int i,j,res,i2cbus,file; 48 int e1, e2 ;49 int e1, e2, e3; 49 50 char filename1[20]; 50 51 char filename2[20]; 52 char filename3[20]; 51 53 char *filename; 52 54 long funcs; … … 70 72 } 71 73 74 /* 75 * Try all three variants and give the correct error message 76 * upon failure 77 */ 78 72 79 sprintf(filename1,"/dev/i2c-%d",i2cbus); 73 80 sprintf(filename2,"/dev/i2c%d",i2cbus); 81 sprintf(filename3,"/dev/i2c/%d",i2cbus); 74 82 if ((file = open(filename1,O_RDWR)) < 0) { 75 83 e1 = errno; 76 84 if ((file = open(filename2,O_RDWR)) < 0) { 77 85 e2 = errno; 78 if(e1 == ENOENT && e2 == ENOENT) { 79 fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n", 80 filename1,filename2,strerror(ENOENT)); 86 if ((file = open(filename3,O_RDWR)) < 0) { 87 e3 = errno; 88 if(e1 == ENOENT && e2 == ENOENT && e3 == ENOENT) { 89 fprintf(stderr,"Error: Could not open file `%s', `%s', or `%s': %s\n", 90 filename1,filename2,filename3,strerror(ENOENT)); 91 } 92 if (e1 != ENOENT) { 93 fprintf(stderr,"Error: Could not open file `%s' : %s\n", 94 filename1,strerror(e1)); 95 if(e1 == EACCES) 96 fprintf(stderr,"Run as root?\n"); 97 } 98 if (e2 != ENOENT) { 99 fprintf(stderr,"Error: Could not open file `%s' : %s\n", 100 filename2,strerror(e2)); 101 if(e2 == EACCES) 102 fprintf(stderr,"Run as root?\n"); 103 } 104 if (e3 != ENOENT) { 105 fprintf(stderr,"Error: Could not open file `%s' : %s\n", 106 filename3,strerror(e3)); 107 if(e3 == EACCES) 108 fprintf(stderr,"Run as root?\n"); 109 } 110 exit(1); 111 } else { 112 filename = filename3; 81 113 } 82 if (e1 != ENOENT) {83 fprintf(stderr,"Error: Could not open file `%s' : %s\n",84 filename1,strerror(e1));85 if(e1 == EACCES)86 fprintf(stderr,"Run as root?\n");87 }88 if (e2 != ENOENT) {89 fprintf(stderr,"Error: Could not open file `%s' : %s\n",90 filename2,strerror(e2));91 if(e2 == EACCES)92 fprintf(stderr,"Run as root?\n");93 }94 exit(1);95 114 } else { 96 115 filename = filename2;
