Forum: Mikrocontroller und Digitale Elektronik ELM Chan Langer Ordner Name


von maik (Gast)


Lesenswert?

Ich arbeite mit der Lib von ElmChan läuft auch alles super.
nun Meine Frage auf meiner SD-Card hab ich mehrere Ordner , die in ihren 
Namen länger als die 8.3 Norm ist.
LFN ist aktiviert.

#define  _USE_LFN  1    /* 0 to 3 */
#define  _MAX_LFN  100    /* Maximum LFN length to handle (12 to 255) */


zb.
Dezember2018

Textdateien mit langer Bezeichnung werden gelesen
zb.
Humidy22.30.2018.001

Was mache ich verkehrt?
1
//###################################################################################
2
FRESULT scan_files_temp (char* path /* Start node to be scanned (also used as work area) */)
3
//###################################################################################  
4
{
5
    FRESULT res;
6
    FILINFO fno;
7
    DIR dir;
8
    int i;
9
    char *fn;   /* This function is assuming non-Unicode cfg. */
10
#if _USE_LFN
11
    static char lfn[_MAX_LFN + 1];
12
    fno.lfname = lfn;
13
    fno.lfsize = sizeof lfn;
14
#endif
15
16
    
17
    res = f_opendir(&dir, path);                       /* Open the directory */
18
    if (res == FR_OK) {
19
        i = strlen(path);
20
        
21
      
22
      for (;;) {
23
        
24
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
25
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
26
            if (fno.fname[0] == '.') continue;             /* Ignore dot entry */
27
#if _USE_LFN
28
            fn = *fno.lfname ? fno.lfname : fno.fname;
29
#else
30
            fn = fno.fname;
31
#endif
32
            if (fno.fattrib & AM_DIR)
33
             {                   /* It is a directory */
34
                sprintf(&path[i], "/%s", fn);
35
                res = scan_files_temp(path);
36
              
37
                strcpy(TEMP_directory[Temp_historyzaehler],fn);
38
         
39
              
40
               
41
                if (res != FR_OK) break;
42
                path[i] = 0;        
43
                Temp_historyzaehler ++; 
44
             
45
             }
46
            
47
            else 
48
            {
49
            }  
50
        }
51
    }
52
  return res;
53
}

von Jim M. (turboj)


Lesenswert?

Du rufst die Funktion rekursiv auf, aber
1
 static char lfn[_MAX_LFN + 1];

ist IMO nicht-reentrant, weil Dir der Unteraufruf den langen Namen 
überschreibt.

von maik (Gast)


Lesenswert?

Jim M. schrieb:
> Du rufst die Funktion rekursiv auf, aber static char lfn[_MAX_LFN
> + 1];
>
> ist IMO nicht-reentrant, weil Dir der Unteraufruf den langen Namen
> überschreibt.

Weenn ich das jetzt so schreibe wie von ihnen vorgeschlagen, wird's auch 
nicht richtig gelesen
1
static char lfn[_MAX_LFN + 1];
2
3
4
//###################################################################################
5
FRESULT scan_files_temp (char* path /* Start node to be scanned (also used as work area) */)
6
//###################################################################################  
7
{
8
    FRESULT res;
9
    FILINFO fno;
10
    DIR dir;
11
    int i;
12
    char *fn;   /* This function is assuming non-Unicode cfg. */
13
#if _USE_LFN
14
    //static char lfn[_MAX_LFN + 1];
15
    fno.lfname = lfn;
16
    fno.lfsize = sizeof lfn;
17
#endif
18
19
    
20
    res = f_opendir(&dir, path);                       /* Open the directory */
21
    if (res == FR_OK) {
22
        i = strlen(path);
23
        
24
      
25
      for (;;) {
26
        
27
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
28
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
29
            if (fno.fname[0] == '.') continue;             /* Ignore dot entry */
30
#if _USE_LFN
31
            fn = *fno.lfname ? fno.lfname : fno.fname;
32
#else
33
            fn = fno.fname;
34
#endif
35
            if (fno.fattrib & AM_DIR)
36
             {                   /* It is a directory */
37
                sprintf(&path[i], "/%s", fn);
38
                res = scan_files_temp(path);
39
              
40
                strcpy(TEMP_directory[Temp_historyzaehler],fn);
41
         
42
              
43
               
44
                if (res != FR_OK) break;
45
                path[i] = 0;        
46
                Temp_historyzaehler ++; 
47
             
48
             }
49
            
50
            else 
51
            {
52
            }  
53
        }
54
    }
55
  return res;
56
}

von maik (Gast)


Lesenswert?

Als Ausgabe für Dezember2018 erhalte ich Dezember~1

Beitrag #5314598 wurde vom Autor gelöscht.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.