473,472 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

scandir and file_select()

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
Aug 20 '08 #1
7 9032
Sheldon said:
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"
Then you're passing the wrong kind of argument to scandir.

In comp.os.linux.development.apps or possibly comp.unix.programmer, I would
imagine that they'd be able to tell you exactly which kind of argument
you're supposed to pass.

<OT>
In BSD4.3, scandir takes int(*)(const struct dirent **, const struct dirent
**) as its third argument, whereas alphasort has the prototype int(const
void *, const void *).
</OT>

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 20 '08 #2
Sheldon <sh******@gmail.comwrote:
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!
scandir() isn't a C standard function so you should instead ask in
comp.unix.programmer (I guess that's what you're using, at least
there is a scandir() function in UNIX that looks familiar to me, if
that guess is wrong look for a group dealing with your sytem). So
here's just an (off-topic) hint: under UNIX the file_select() func-
tion is supposed to take a const struct dirent pointer as its argu-
ment, note the const qualifier and the difference between the words
'direct' and 'dirent'.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Aug 20 '08 #3
On 20 Aug, 14:33, j...@toerring.de (Jens Thoms Toerring) wrote:
Sheldon <shejo...@gmail.comwrote:
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!

scandir() isn't a C standard function so you should instead ask in
comp.unix.programmer (I guess that's what you're using, at least
there is a scandir() function in UNIX that looks familiar to me, if
that guess is wrong look for a group dealing with your sytem). So
here's just an (off-topic) hint: under UNIX the file_select() func-
tion is supposed to take a const struct dirent pointer as its argu-
ment, note the const qualifier and the difference between the words
'direct' and 'dirent'.
Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de
Thanks guys! I'll go on to the linux group.

/S
Aug 20 '08 #4
On Wed, 20 Aug 2008 12:30:15 +0000, Richard Heathfield wrote:
Sheldon said:
>"warning: passing argument 3 of 'scandir' from incompatible pointer
type"

Then you're passing the wrong kind of argument to scandir.

In BSD4.3, scandir takes int(*)(const struct dirent **, const struct
dirent **) as its third
fourth
argument, whereas alphasort has the prototype
int(const void *, const void *).
Aug 20 '08 #5
On Wed, 20 Aug 2008 05:03:18 -0700, Sheldon wrote:

Add:

int file_select(struct direct *entry);

before

int read_files() {
Aug 20 '08 #6
viza said:
On Wed, 20 Aug 2008 12:30:15 +0000, Richard Heathfield wrote:
>Sheldon said:
>>"warning: passing argument 3 of 'scandir' from incompatible pointer
type"

Then you're passing the wrong kind of argument to scandir.

In BSD4.3, scandir takes int(*)(const struct dirent **, const struct
dirent **) as its third

fourth
Oh yes. Thank you. Well, in that case he actually got (at least!) two args
wrong.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 20 '08 #7
viza <to******@gm-il.com.obviouschange.invalidwrites:
On Wed, 20 Aug 2008 05:03:18 -0700, Sheldon wrote:

Add:

int file_select(struct direct *entry);

before

int read_files() {
Yes, that could be part of the problem. In the code fragment Sheldon
posted, there's no visible prototype for file_select at the point
where its name is used in the call to scandir. In C90 mode, the
compiler will assume that a function with no visible declaration
returns int. (C99 dropped implicit int.)

Also, read_files is declared with no prototype:

int read_files() { ... }

This is legal, but rarely a good idea. If it takes no arguments,
say so:

int read_files(void) { ... }

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 20 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: David Callan | last post by:
Hi folks, I'm starting to develop my final year project for college. Just set up dreamweaver site environment. My local machine is windows based running php 5 while my remote machine is unix based...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
15
by: Hemant Shah | last post by:
Folks, We have an SQL statement that was coded in an application many years ago (starting with DB V2 I think). When I upgraded to UDB 8.2, the optimizer does not use optimal path to access the...
9
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
4
by: JR | last post by:
I need some help. I am trying to return a dirent struct location so i can access what the function found in main(). I dont understand pointers very well and think that is were i am getting it...
2
by: CptDondo | last post by:
I've got an issue that I can't figure out.... It has to do with a compiler warning: warning: passing arg 3 of `scandir' from incompatible pointer type Now scandir is declared in dirent.h: ...
165
by: Dieter | last post by:
Hi. In the snippet of code below, I'm trying to understand why when the struct dirent ** namelist is declared with "file" scope, I don't have a problem freeing the allocated memory. But...
2
by: René Kälin | last post by:
Hi! I've got a tiny little problem :-) with the following code: .... function get_styles($dir) { $tmp = scandir($dir); // Line 19 echo $dir; echo $tmp; foreach ($tmp as $key => $datei) {
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.