mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-29 21:08:19 +00:00
Refactor i2c device opening.
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2675 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
680fc92ede
commit
1cc6544e2b
4 files changed
+45
-114
No files matched your search
+1
-29
@@ -25,7 +25,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "../dump/i2cbusses.h"
|
||||
#include "i2c-dev.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
#define MODE_QUICK 1
|
||||
#define MODE_READ 2
|
||||
|
||||
void print_i2c_busses(int);
|
||||
|
||||
void help(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
@@ -49,23 +47,6 @@ void help(void)
|
||||
print_i2c_busses(0);
|
||||
}
|
||||
|
||||
int open_i2c_dev(const int i2cbus, char *filename)
|
||||
{
|
||||
int file;
|
||||
|
||||
sprintf(filename, "/dev/i2c-%d", i2cbus);
|
||||
file = open(filename, O_RDWR);
|
||||
|
||||
if (file >= 0 || errno != ENOENT) {
|
||||
return file;
|
||||
}
|
||||
|
||||
sprintf(filename, "/dev/i2c/%d", i2cbus);
|
||||
file = open(filename, O_RDWR);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
int scan_i2c_bus(int file, const int mode, const int first, const int last)
|
||||
{
|
||||
int i, j;
|
||||
@@ -231,15 +212,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
file = open_i2c_dev(i2cbus, filename);
|
||||
if (file < 0) {
|
||||
if (errno == ENOENT) {
|
||||
fprintf(stderr, "Error: Could not open file `/dev/i2c-%d' or `/dev/i2c/%d': %s\n",
|
||||
i2cbus, i2cbus, strerror(ENOENT));
|
||||
} else {
|
||||
fprintf(stderr, "Error: Could not open file `%s': %s\n",
|
||||
filename, strerror(errno));
|
||||
if (errno == EACCES)
|
||||
fprintf(stderr, "Run as root?\n");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user