[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: changing directories and getting filedates

Felix Kollmann wrote:

> > >...getting the time and date of a file (packed).
> >
> > stat(2)
> Does not work correctly. Every time I get a SIGSEGV.

Hmm, I would rather bet on you not *using* it correctly, because "ls"
calls stat() like crazy and it seems to work fine, no? :-)

You have to pass it a block of memory of the right size. The easiest way
is this code snippet:

struct stat statbuf;

stat("/some/file", &statbuf);

'statbuf' should then contains what you want (hmm, check the return
value, m'kay?)...

> > chdir(2)
> Does not work correctly. The directories created with mkdir are
> unsccessable by the programme.

I bet that your "mode" argument to mkdir() was 0. Create your directory
with mkdir("/the/dir/to/create", 0777) and you should be able to then
use chdir to go in it (the "0" in "0777" is important, so that the
compiler knows that this is octal and not decimal, and for those
worrying about 0777 permissions, the umask will remove some of that,
just be happy).

*Always* check the return value for system calls like that (hint: system
calls are the ones that their man page has the number 2, printf and
"normal" calls are in chapter 3).

Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi