View Full Version : Problem with lstat function in C

September 11th, 2005, 01:40 PM
I am trying to use g_lstat to obtain the attributes of a file.
Partial source code:

#include <glib.h>
#include <glib/gstdio.h>

struct stat *filedata;
guint result;

result = g_lstat(filename,filedata);

I am getting a compiler error:

"warning: implicit declaration of function `lstat'"

There are no other error messages.

g_lstat is #defined as lstat in gstdio.h.

gstdio.h #includes <sys/stat.h>, (which defines lstat) so I shouldn't have to include it myself.

As expected, adding it to my source file does not solve the problem, nor does adding all the #includes shown by 'man lstat':

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

I have checked for stat.h on my system - it is under /usr/include/sys/.

What else should I check?

Thanks for any advice,

Kevin ](*,)

September 11th, 2005, 05:32 PM
Posting your entire source file and the entire error message would be very helpful.

September 11th, 2005, 11:28 PM

the entire error message is as shown, and is caused by the line which includes 'g_lstat'.
The entire source file is way too long to post, and is mostly not relevant to the problem.

I have just discovered that I can lose the error message by replacing 'g_lstat' with 'gstat', or I can keep 'g_lstat' and remove the '-ansi' flag from my makefile.

It seems that 'stat' is ansi compliant, but 'lstat' is not.


September 11th, 2005, 11:47 PM
Well clearly, the issue isn't in what you posted.

My guess is that you have your include files in the wrong order, but that's just me.

October 5th, 2011, 10:53 PM
lstat() is not compliant with strict ANSI. Change your compiler flags.

I had this flag:

-std=c99changed it to this:

-std=gnu99and it compiles fine!

October 5th, 2011, 11:03 PM
Does anyone know what the record for necro-bumping is? ;)

October 5th, 2011, 11:41 PM
Does anyone know what the record for necro-bumping is? ;)

:lolflag:Oh well at least now if someone runs into this problem and googles it(it's the first result) will at least have a solution.