[plt-scheme] Where to find out that library objects like "chmod" are available in the underlying implementation?

From: Ernie Smith (esmith at acanac.net)
Date: Thu Oct 2 17:43:35 EDT 2008

I picked this out of the thread:

>Re: [plt-scheme] Is there any way to make a file writable?
>> (If I need to make an ffi call to 'system', any hints on exactly
>> which lib-ffi I need to load?)
>
>That's easy:
>  (require (lib "foreign.ss")) (unsafe!)
>  (define chmod (get-ffi-obj "chmod" #f (_fun _path _int -> _void)))
>  (chmod "some-path" #o644)

Easy indeed. I tried it. It works.

Now here are my questions:

1- Where would I have needed to look to find out that "chmod" is available
   like that when the lib argument is #f?

2- What other underlying system calls are available?

   The one that would suit me right now would be 'stat'.
   I'm attempting to write a script that traverses the file
   system on a specific device.  

   (fold-files ..) almost does the trick but...

   I need to prune cross-device directory transitions.  
   That would be easy enough by monitoring transitions in 
   device number using "stat".

   I also need to ignore all the special files one tends
   to find on unix systems, i.e. filter for 'regular files'
   not named pipes, special device files etc..
   
   The frustrating thought I've been having is that in order to implement
   (fold-files ...) the underlying software is likely using "stat". 
   
   I'm hoping this post has two effects.  
   1- A nice quick easy answer like Eli Barzilay came up with for "chmod".
   2- This inspires someone on the PLT team to come up with an improved 
      (fold-files ..) that makes the desire for "stat" ffi calls at this level 
      go away.

   BTW I'm still on 372

TIA





Posted on the users mailing list.