fallback when devfs names aren't found
[openwrt.git] / package / mtd / src / mtd.c
index 7d1e360..0a96840 100644 (file)
@@ -197,13 +197,18 @@ mtd_open(const char *mtd, int flags)
        FILE *fp;
        char dev[PATH_MAX];
        int i;
        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 ((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);
                                fclose(fp);
-                               return open(dev, flags);
+                               return ret;
                        }
                }
                fclose(fp);
                        }
                }
                fclose(fp);
This page took 0.021114 seconds and 4 git commands to generate.