chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] [PATCH] drop ##sys#file-info


From: Alan Post
Subject: Re: [Chicken-hackers] [PATCH] drop ##sys#file-info
Date: Mon, 3 Oct 2011 09:18:53 -0601

On Sun, Oct 02, 2011 at 01:33:11PM +0200, Felix wrote:
> This patch replaces ##sys#file-info with a cleaner file/directory
> exists check. It checks for errors (except ENOENT) and can later be
> extended to handle EOVERFLOW on those platforms that support some
> workaround or large file support. "fifo?" was also changed to use
> stat(3) and checks for errors instead of using ##sys#file-info.
> 
> The patch was done in collaboration with Christian, but I post it
> here once more in case someone wants to comment.
> 
> 
> cheers,
> felix

> From 71eb0e713084f670d9f2cebc1f475ba25d779b3a Mon Sep 17 00:00:00 2001
> From: felix <address@hidden>
> Date: Fri, 30 Sep 2011 09:17:01 +0200
> Subject: [PATCH 1/2] replaced ##sys#file-info with ##sys#file-exists?
> 
> ---
>  c-platform.scm |    3 +-
>  chicken.h      |    2 +-
>  eval.scm       |   20 +++++---------
>  library.scm    |   22 ++++++++++++---
>  posixunix.scm  |   31 +++++++++++++++++++---
>  posixwin.scm   |    9 +------
>  runtime.c      |   77 
> ++++++++++++++++----------------------------------------
>  7 files changed, 77 insertions(+), 87 deletions(-)
> 
> diff --git a/posixunix.scm b/posixunix.scm
> index a9e4565..5cde5b8 100644
> --- a/posixunix.scm
> +++ b/posixunix.scm
> @@ -468,6 +468,26 @@ static int set_file_mtime(char *filename, C_word tm)
>    return utime(filename, &tb);
>  }
>  
> +static C_word C_i_fifo_p(C_word name) 
> +{
> +  struct stat buf;
> +  int res;
> +
> +  res = stat(C_c_string(name), &buf);
> +
> +  if(res != 0) {
> +#ifdef __CYGWIN__
> +    return C_SCHEME_FALSE;
> +#else
> +    if((buf.st_mode & S_IFMT) == S_IFIFO) return C_SCHEME_TRUE;
> +    else return C_SCHEME_FALSE;
> +#endif
> +  }
> +
> +  if(errno == ENOENT) return C_fix(0);
> +  else return C_fix(res);
> +}
> +
>  EOF
>  ) )
>  

I *think* by my reading of this routine there is a subtle problem
here.

errno is only set when a syscall returns -1/signals an error.  If
you call stat and it succeeds, errno wasn't touched by stat, and
has whatever value it did before stat was called.

>From the look of this routine, you're checking errno in the success
case, where stat returned 0.  If that is the case, the errno value
is not set by stat and has whatever value it already had.    

Do I read that correctly?

-Alan
-- 
.i ma'a lo bradi cu penmi gi'e du



reply via email to

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