Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

scandir and file_select()

34 views
Skip to first unread message

Sheldon

unread,
Aug 20, 2008, 7:58:49 AM8/20/08
to
Hi,

I have a little warning that I am trying to understand but it escapes
me. Perhaps someone can help here.
I have the function read_files() that scans the directory and return
the desired file names after filtering.
I have used the function file_select() to filter out unwanted files
and everything works nicely except that I keep getting the warning:

"warning: passing argument 3 of 'scandir' from incompatible pointer
type"

********

int read_files() {
/* Read directory and find desired files */
/* file_select is used to sort the files and fetch the desired files
*/
return scandir(DIR, &list, file_select, alphasort);
}

int file_select(struct direct *entry) {
if (strstr(entry->d_name,FILTER1) && strstr(entry->d_name,FILTER2)
&& strstr(entry->d_name,FILTER3)) {
return TRUE;
} else {
return FALSE;
}
}


Can someone enlighten me please!

/S

Daniel

unread,
Aug 20, 2008, 12:13:29 PM8/20/08
to

It seems to me that function's return type is wrong. I'm not sure what
should be return by 3rd parameter of scandir, but function returns
boolean value, while its return type is integer.

Regards,
Daniel

Jędrzej Dudkiewicz

unread,
Aug 20, 2008, 1:06:20 PM8/20/08
to
Sheldon wrote:
> Hi,
>
> I have a little warning that I am trying to understand but it escapes
> me. Perhaps someone can help here.
> I have the function read_files() that scans the directory and return
> the desired file names after filtering.
> I have used the function file_select() to filter out unwanted files
> and everything works nicely except that I keep getting the warning:
>
> "warning: passing argument 3 of 'scandir' from incompatible pointer
> type"

Declaration of scandir goes like this:

int scandir(const char *dir, struct dirent ***namelist,
int(*filter)(const struct dirent *),
int(*compar)(const struct dirent **, const struct dirent
**));

Note "const" modifier in filter's declaration. Change your file_select to:

int file_select(struct dirent const*)

JD

0 new messages