using gdb

Jerry Feldman gaf at blu.org
Mon Jul 15 17:54:47 EDT 2002


With the stat family of functions, you provide a pointer to a buffer. 
Essentially:
{
	struct stat buffer;
	rc = stat("<path to file>, &buffer);

The stat(2) function will fill in the fields for you. A possible 
programming error is:
{
	struct stat *buffer;
	rc = stat("<path to file>, buffer);

In this case, you are not allocating any space. Since buffer is a pointer 
on the stack, it may contain any garbage, including a valid address. So, 
the kernel is actually wrting into whatever buffer points to. 

I generally set up a function to call stat() or fstat(), and take the 
information I need either within the function or return it, sike file size, 
depending on what I need stat for. The stat(2) family of system calls is 
used by the ls command as well as many other Unix/Linux commands.  
On 15 Jul 2002 at 16:30, Brad Noyes wrote:

> I did just find out what the problem is that i'm having. I appears that two of
> my stat structs are over-lapping slightly in memory. I don't know exactlly where 
> in the code to fix this (i'll find it eventually), but using DDD was key. It was 
> able to display all the numbers that changed from on line of code to the next.

--
Jerry Feldman <gaf at blu.org>
Associate Director
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9




More information about the Discuss mailing list