scandir() function issue on Red Hat...

Post questions regarding programming in C/C++ in Linux/Unix.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

scandir() function issue on Red Hat...

Postby palakdebnath » Thu Feb 19, 2009 3:55 pm

Hi,

I'm using scandir function in my application running on Red Hat Linux. Here I found that the prototype of compare function is different than the man page in man page it is showing -

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

but in dirent.h it is
extern int scandir (__const char *__restrict __dir,
struct dirent ***__restrict __namelist,
int (*__selector) (__const struct dirent *),
int (*__cmp) (__const void *, __const void *))


Look at the prototype of compare function. in my code changed compare function prototype as declared on dirent.h file. But I'm not getting desired result on Red Hat. Is there any problem in scandir()? Not sure, due to that I'm getting coredump. Please HELP me.

Any help will be appriciated. Thanks in advance.

Thanks,
Palak
palakdebnath
 
Posts: 24
Joined: Wed Jun 04, 2008 4:21 pm

Postby Alvaro » Thu Feb 19, 2009 9:46 pm

Funny that. I have openSUSE and it has the same problem.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby MXP » Thu Feb 19, 2009 11:08 pm

Sounds like you should file a bug against whomever owns that documentation :)
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Alvaro » Thu Feb 19, 2009 11:27 pm

Here is some working code which might help you in solving your problem:
[syntax="cpp"]#include <iostream>
#include <dirent.h>

int lengthsort(const void *p1, const void *p2) {
const struct dirent * const * d1 = reinterpret_cast<const struct dirent * const *>(p1);
const struct dirent * const * d2 = reinterpret_cast<const struct dirent * const *>(p2);
return (*d1)->d_namlen-(*d2)->d_namlen;
}

int main() {
struct dirent **namelist;

int n_entries = scandir(".", &namelist, 0, lengthsort);
for(int i=0; i<n_entries; ++i) {
std::cout << namelist[i]->d_name << '\n';
}
free(namelist);
}
[/syntax]
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby palakdebnath » Fri Feb 20, 2009 11:44 am

Thanks Alvaro and Colin....

Now I'm getting following core dump -

Program received signal SIGABRT, Aborted.

It is happenning when I'm trying to free a 2D array pointer. Before calling free() I'm check whether it is pointing to 0 (NULL) or not. What does SIGABRT means?

Thanks,
Palak
palakdebnath
 
Posts: 24
Joined: Wed Jun 04, 2008 4:21 pm

Postby Alvaro » Fri Feb 20, 2009 12:24 pm

SIGABRT indicates an abnormal program termination. It is likely that you have corrupted the heap. This can happen in a number of ways, like releasing a block twice, calling free() on a block that was allocated with new, calling delete on a block that was allocated with malloc(), trying to release a block that was never allocated...

Memory corruption problems are hard to pin down. Review your code carefully, try debugging it to understand what it's doing better, and if you still can't find the problem, use a tool like Valgrind or Purify to get detailed information of how you are using memory.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby palakdebnath » Fri Feb 20, 2009 6:07 pm

Hi Alvaro,

In my application I have malloc as wel as calloc statements. We want to replace those with new operator. for malloc I can replace with only new. But for calloc shall I replace with a new and a memset() function call, right?

Thanks,
Palak
palakdebnath
 
Posts: 24
Joined: Wed Jun 04, 2008 4:21 pm

Postby MXP » Sun Feb 22, 2009 12:59 am

Right.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Re: scandir() function issue on Red Hat...

Postby mylanguage » Fri May 20, 2011 4:56 pm

Bumping this topic for good reason as I have been doing a majority of my activity on this forum through the search forum. Was there ever any conclusion as to why the same problem was happening within BOTH RedHat and openSUSE? This seems a bit peculiar to me, and it seems like it may be overcome by hosting some of the files in the cloud once we know they are efficient. I have been experiment ting with different cloud service opportunities and feel like this could be a good fix moving forward. So far the media files I converted with youtube to mp3 converter software are being embedded fine from the cloud.
Last edited by mylanguage on Tue Jan 17, 2012 4:29 pm, edited 1 time in total.
User avatar
mylanguage
 
Posts: 6
Joined: Thu May 19, 2011 10:49 am

Re: scandir() function issue on Red Hat...

Postby ventsyv » Tue Jul 19, 2011 8:08 am

Stop spamming please. OK, I get it, you are promoting the colud server thing ... Just start a thread in the "Open Discussion" sub-forum and post your thing - what exactly are you offering and at what price...
User avatar
ventsyv
 
Posts: 2810
Joined: Mon Sep 22, 2003 5:25 pm
Location: MD USA

Re: scandir() function issue on Red Hat...

Postby swain » Mon Nov 21, 2011 11:45 pm

I think this issue has also been found in openSUSE. I would recommend you to see if there is any indication of a corrupted heap. If so, try carefully analyzing the code and debug it. I think there are third party tools like Purify and Valgrind which would assist you on this.I have been lately concenterating heavily on logo design and it has really given me some stunning logos.Now thinking about selling it.
“Read Today, Lead Tomorrow”
swain
 
Posts: 4
Joined: Sat Nov 12, 2011 3:26 am

Re: scandir() function issue on Red Hat...

Postby Bilal » Mon Dec 26, 2011 3:44 am

I too am experiencing similar issues with Red Hat and despite changing the codes, I am not making any particular progress I am intending to. I too am suspecting Scandir to have some issues. Anyway, I guess I need to work around with coredump in order to rectify this issue.
Bilal
 
Posts: 2
Joined: Mon Dec 26, 2011 3:42 am


Return to Unix/Linux

Who is online

Users browsing this forum: No registered users and 0 guests

cron