Show
Ignore:
Timestamp:
03/31/01 21:00:45 (11 years ago)
Author:
mds
Message:

add devfs /dev/i2c/x support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/detect/i2cdetect.c

    r847 r1053  
    22    i2cdetect.c - Part of i2cdetect, a user-space program to scan for I2C  
    33                  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> 
    56 
    67    This program is free software; you can redistribute it and/or modify 
     
    4647  char *end; 
    4748  int i,j,res,i2cbus,file; 
    48   int e1, e2; 
     49  int e1, e2, e3; 
    4950  char filename1[20]; 
    5051  char filename2[20]; 
     52  char filename3[20]; 
    5153  char *filename; 
    5254  long funcs; 
     
    7072  } 
    7173 
     74/* 
     75 * Try all three variants and give the correct error message 
     76 * upon failure 
     77 */ 
     78 
    7279  sprintf(filename1,"/dev/i2c-%d",i2cbus); 
    7380  sprintf(filename2,"/dev/i2c%d",i2cbus); 
     81  sprintf(filename3,"/dev/i2c/%d",i2cbus); 
    7482  if ((file = open(filename1,O_RDWR)) < 0) { 
    7583    e1 = errno; 
    7684    if ((file = open(filename2,O_RDWR)) < 0) { 
    7785      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; 
    81113      } 
    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); 
    95114    } else { 
    96115       filename = filename2;