[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Using errno for reporting errors in open-*-file
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Using errno for reporting errors in open-*-file |
Date: |
Thu, 24 Mar 2005 08:08:22 +0100 |
On Wed, 23 Mar 2005 12:42:09 -0500, Alejandro Forero Cuervo
<address@hidden> wrote:
>
> I have recently noticed that, on errors, many functions (such as
> open-input-file, open-output-file, rename-file and delete-file) don't
> use errno for describing the error. They use a standard message such
> as "can not open file" instead of a more descriptive one such as "No
> such file or directory" or "Permission denied". Shouldn't the error
> they generate be based on the description provided by the underlying
> kernel/C library?
Yes, that sounds reasonable.
>
> If anyone can explain how to accomplish this with, say,
> open-input-file, I would gladly help apply it to other functions.
Don't worry. I'll add this. Perhaps you can give me a list of
procedures for which you wish error-messages that use
strerror(3) ?
>
> I've been looking at runtime.c and library.scm, but I'm not sure how
> it should be done. Should library.scm look at the value returned by
> the Scheme-level errno procedure and call a wrapper to strerror or
> should an additional argument be passed to C_open_file_port (and
> similar functions) so they can return a pointer to a string describing
> the error? Can anyone point me to an example as to how a C procedure
> can create a Scheme string with the contents of a given char *
> (hopefully without having to copy the contents)?
You normally can do just this:
(define-foreign-variable strerror c-string "strerror(errno)")
(pp strerror)
(handle-exceptions ex (pp strerror) (open-input-file "kjshdfjhdfg"))
I have changed open-[input|output]-file, and [rename|delete]-file
accordingly. If you need any others, just tell me.
cheers,
felix