lsflib/src/md5recursive.c
changeset 136 d82f65e902d0
parent 121 fef2ccfa7b12
child 150 75133486ba7e
equal deleted inserted replaced
135:f837cf975e95 136:d82f65e902d0
    28         perror (root);
    28         perror (root);
    29         return;
    29         return;
    30     }
    30     }
    31 
    31 
    32     while ((entry = readdir (directory))) {
    32     while ((entry = readdir (directory))) {
    33         list = (char *)malloc (strlen (root) + 1 + strlen (entry->d_name) + 1);
    33         if ((!strcmp (entry->d_name, ".")) || (!strcmp (entry->d_name, "..")))
    34 
       
    35         if (list == NULL) {
       
    36             perror ("malloc");
       
    37             return;
       
    38         }
       
    39 
       
    40         sprintf (list, "%s/%s", root, entry->d_name);
       
    41 
       
    42         if (!strcmp (entry->d_name, "."))
       
    43             continue;
    34             continue;
    44 
    35 
    45         if (!strcmp (entry->d_name, ".."))
    36         list = malloc (strlen (root) + 1 + strlen (entry->d_name) + 1);
    46             continue;
    37         sprintf (list, "%s/%s", root, entry->d_name);
    47 
    38 
    48         if (isDir (list)) {
    39         if (isDir (list)) {
    49             fprintf (stderr, "Directory: %s\n", list);
    40             fprintf (stderr, "Directory: %s\n", list);
    50             if (recursive) {
    41             if (recursive) {
    51                 md5recursive (list, recursive);
    42                 md5recursive (list, recursive);
    52             }
    43             }
       
    44             free (list);
    53             continue;
    45             continue;
    54         }
    46         }
    55 
    47 
    56         if ((value = md5sum (list)) == NULL) {
    48         if ((value = md5sum (list)) == NULL) {
    57             continue;
    49             continue;
    58         }
    50         }
    59 
    51 
    60         for (i = 0; i < 16; i++)
    52         for (i = 0; i < 16; i++)
    61             printf ("%02x", value[i]);
    53             printf ("%02x", value[i]);
    62         printf ("  %s\n", list);
    54         printf ("  %s\n", list);
       
    55         free (list);
    63         free (value);
    56         free (value);
    64     }
    57     }
    65 
    58 
    66     free (list);
       
    67     closedir (directory);
    59     closedir (directory);
    68 }
    60 }