1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| int lib_string_scan_dir_file (char *path, const char *name, char **out)
{
DIR *d, *sd;
struct dirent *entry;
char dir[SIZESIGN][SIZESIGN];
char buffer[SIZESIGN];
int i, k, ndir = 0;
strncpy (dir[ndir++], path, SIZESIGN-1);
d = opendir (dir[0]);
if (d == NULL)
return 1;
while ((entry = readdir (d)))
{
if ((!strcmp (entry->d_name, ".")) || (!strcmp (entry->d_name, "..")))
{
}
else
{
snprintf (buffer, SIZESIGN-1, "%s%c%s", path, SEP, entry->d_name);
sd = opendir (buffer);
if (sd != NULL)
{
k = snprintf (dir[ndir++], SIZESIGN-1, "%s", buffer);
if ((k < 0) && (k >= SIZESIGN))
{
dir[ndir][0] = '\0';
ndir--;
}
}
else
{
if (!strcmp (entry->d_name, name))
{
k = snprintf (*out, SIZESIGN-1, "%s%c%s", path, SEP, entry->d_name);
if ((k < 0) && (k >= SIZESIGN))
return 2;
else
return 0;
}
}
}
}
for (i = 1; i < ndir; i++)
{
k = lib_string_scan_dir_file (dir[i], name, out);
if (k == 0)
return k;
}
return 1;
} |
Partager