![background image](http://html1.mh-extra.com/html/ibase-technology/ib113/ib113_user-manual_3233460053.webp)
52
IB113
len_algo = rtrim(algo);
name = strrchr(s, '\t');
*(name++) = '\0';
len_name = rtrim(name);
type = strrchr(s, '\t');
*(type++) = '\0';
len_type = rtrim(type);
sscanf(s, "i2c-%d", &i2cbus);
if ((count + 1) % BUNCH == 0) {
/* We need more space */
adapters = more_adapters(adapters, count + 1);
if (!adapters)
return NULL;
}
all = malloc(le le len_algo);
if (all == NULL) {
free_adapters(adapters);
return NULL;
}
adapters[count].nr = i2cbus;
adapters[count].name = strcpy(all, name);
adapters[count].funcs = strcpy(all + len_name, type);
adapters[count].algo = strcpy(all + le len_type,
algo);
count++;
}
fclose(f);
goto done;
}
/* look in sysfs */
/* First figure out where sysfs was mounted */
if ((f = fopen("/proc/mounts", "r")) == NULL) {
goto done;
}
while (fgets(n, NAME_MAX, f)) {
sscanf(n, "%*[^ ] %[^ ] %[^ ] %*s\n", sysfs, fstype);
if (strcasecmp(fstype, "sysfs") == 0) {
fou+;
break;
}
}
fclose(f);
if (! foundsysfs) {
goto done;
}
/* Bus numbers in i2c-adapter don't necessarily match those in
i2c-dev and what we really care about are the i2c-dev numbers.
Unfortunately the names are harder to get in i2c-dev */
strcat(sysfs, "/class/i2c-dev");
if(!(dir = opendir(sysfs)))
goto done;
/* go through the busses */
while ((de = readdir(dir)) != NULL) {
if (!strcmp(de->d_name, "."))
continue;
if (!strcmp(de->d_name, ".."))
continue;
/* this should work for kernels 2.6.5 or higher and */
/* is preferred because is unambiguous */
sprintf(n, "%s/%s/name", sysfs, de->d_name);
f = fopen(n, "r");
/* this seems to work for ISA */