[Top][All Lists]

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

[Chicken-users] Lstat problems

From: Matt Gushee
Subject: [Chicken-users] Lstat problems
Date: Wed, 20 Apr 2005 10:54:01 -0600
User-agent: Mozilla Thunderbird 1.0 (X11/20050108)

Hello, all--

I am writing an application that needs to distinguish between regular files, symlinks, directories, devices, sockets, and fifos *without* dereferencing symlinks ... so it requires lstat(). Since the Chicken library doesn't provide an lstat() wrapper, I decided to try to write one myself. Well, I'm not much of a C programmer (as you can probably tell with a glance at my code); the following sort-of works, but after a couple of invocations it segfaults ... and apparently it corrupts an area of memory, since after the first segfault it continues to segfault until I reboot. So, what do I need to do to make this solid?

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

  (define file-ltype
    (foreign-lambda* int ((c-string filename))
      "struct stat *statbuf;
       int result, mode;
       result = lstat(filename, statbuf);
       mode = statbuf->st_mode;
       return (S_IFMT & mode);"))

BTW, I was planning to handle cases like files not existing in Scheme code. I figure that since I don't really know what I'm doing, the less I do in C the better.

Matt Gushee
Englewood, CO, USA

reply via email to

[Prev in Thread] Current Thread [Next in Thread]