[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in
From: |
Alan Post |
Subject: |
Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists? |
Date: |
Sat, 8 Oct 2011 10:48:36 -0601 |
On Sat, Oct 08, 2011 at 03:11:29PM +0200, Felix wrote:
> This patches avoids an error when "[file|directory]-exists?" gets
> EOVERFLOW or ENOTDIR, which indicate an existing or no-existing file,
> respectively.
>
>
> cheers,
> felix
>
>
> commit 473edf9428a7bc38fc033e86d0bbcb362f1cd2d8
> Author: felix <address@hidden>
> Date: Sat Oct 8 15:09:42 2011 +0200
>
> handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?
>
> diff --git a/runtime.c b/runtime.c
> index a6d7919..f9f8459 100644
> --- a/runtime.c
> +++ b/runtime.c
> @@ -9246,8 +9246,12 @@ C_i_file_exists_p(C_word name, C_word file, C_word dir)
> res = stat(C_c_string(name), &buf);
>
> if(res != 0) {
> - if(errno == ENOENT) return C_SCHEME_FALSE;
> - else return C_fix(res);
> + switch(errno) {
> + case ENOENT: return C_SCHEME_FALSE;
> + case EOVERFLOW: return C_truep(dir) ? C_SCHEME_FALSE : C_SCHEME_TRUE;
> + case ENOTDIR: return C_SCHEME_FALSE;
> + default: return C_fix(res);
> + }
> }
>
> switch(buf.st_mode & S_IFMT) {
I'm only *half* kidding when I say I would write the switch
statement like this:
switch(errno) {
case EOVERFLOW:
if (C_truep(dir)) {
case ENOENT:
case ENOTDIR:
return C_SCHEME_FALSE;
} else {
return C_SCHEME_TRUE;
}
}
On OpenBSD, I think you'd like to handle ENAMETOOLONG by returning
C_SCHEME_FALSE too. On that platform, EOVERFLOW is not returned
from stat. (And I'm not sure what it is signalling, so I don't
know what this if statement is checking for.)
Will you add a check for ENAMETOOLONG?
Why is the order of errno values like it is? If you think weaving
an if statement with a switch statement isn't me half kidding,
should they instead be in alphabetical order?
In general I think these kinds of detailed checks are a fantastic
idea, and we're going to find not every platform returns the same
errno value for a particular error condition.
-Alan
--
.i ma'a lo bradi cu penmi gi'e du
- [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Felix, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Christian Kellermann, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?,
Alan Post <=
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Christian Kellermann, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Alan Post, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Christian Kellermann, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Alan Post, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Christian Kellermann, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Alan Post, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Christian Kellermann, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, John Cowan, 2011/10/08
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, John Cowan, 2011/10/10
- Re: [Chicken-hackers] [PATCH] handle EOVERFLOW and ENOTDIR gracefully in file/directory-exists?, Christian Kellermann, 2011/10/10