fallback when devfs names aren't found

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@6541 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Mike Baker 2007-03-09 08:58:37 +00:00
parent 0c7837df28
commit 5660ba0198
1 changed files with 6 additions and 1 deletions

View File

@ -197,13 +197,18 @@ mtd_open(const char *mtd, int flags)
FILE *fp;
char dev[PATH_MAX];
int i;
int ret;
if ((fp = fopen("/proc/mtd", "r"))) {
while (fgets(dev, sizeof(dev), fp)) {
if (sscanf(dev, "mtd%d:", &i) && strstr(dev, mtd)) {
snprintf(dev, sizeof(dev), "/dev/mtd/%d", i);
if ((ret=open(dev, flags))<0) {
snprintf(dev, sizeof(dev), "/dev/mtd%d", i);
ret=open(dev, flags);
}
fclose(fp);
return open(dev, flags);
return ret;
}
}
fclose(fp);