[racket] Detecting named pipe

From: Danny Yoo (dyoo at hashcollision.org)
Date: Sun Sep 2 19:08:48 EDT 2012

On Sun, Sep 2, 2012 at 6:25 AM, Paulo J. Matos <paulo at matos-sorge.com> wrote:
> Hi,
> I am trying to obtain the md5sum of a bunch of files, so for all files with
> path 'p' I do : (call-with-input-file p md5)
> The problem is that this hangs when I find a named pipe file. file-exists?
> returns #t and then the process hangs. It seems I can't run md5 on named
> pipes, so how can I check if a file is a named pipe?

Hi Paulo!

I would have assumed the 'stat' call would be available from Racket.
Does anyone else know if 'stat' is exposed by some built-in library?

There's a PLaneT package synx/stat that is unfortunately undocumented,
but it may be helpful.


Here's an example of its usage.  Let's say that I've created a named pipe:

    mithril:~ dyoo$ mkfifo my_pipe

Then I can go into Racket and see if it looks like a regular file:

    mithril:~ dyoo$ racket
    Welcome to Racket v5.3.
    > (require (planet synx/stat))
    > (normal-file? (type-bits "my_pipe"))

In comparison, other files will report that they are regular files.
For example:

> (for ([file (take (directory-list) 5)])
  (printf "normal file? ~a ~a\n" file (normal-file? (type-bits file))))

normal file? .android #f
normal file? .appcfg_cookies #t
normal file? .argouml #f
normal file? .bash_history #t
normal file? .bashrc #t

And that matches up for me: in my home directory, .android and
.argouml are directories, and the rest are plain files.

It would be really nice if this package were polished and documented,
as this sort of thing is useful.

Posted on the users mailing list.