[PATCH] If EAGAIN == EWOULDBLOCK, only need to check errno for one of them

Peter Hutterer peter.hutterer at who-t.net
Sun Jan 5 17:05:38 PST 2014


On Sat, Jan 04, 2014 at 12:09:45AM -0800, Alan Coopersmith wrote:
> Solaris <sys/errno.h> has:
>  #define EWOULDBLOCK       EAGAIN
> so checking (errno == EAGAIN || errno == EWOULDBLOCK) is overkill.
> 
> This leads cppcheck 1.62 to complain:
> [xserver/os/io.c:365] -> [xserver/os/io.c:365]: (style) Same expression on both sides of '||'.
> [xserver/os/io.c:941] -> [xserver/os/io.c:941]: (style) Same expression on both sides of '||'.
> 
> This quiets it, and reduces the number of calls Solaris Studio cc
> generates to the __errno() function to get the thread-specific errno value.
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

Cheers,
   Peter


> ---
>  os/io.c |   11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/os/io.c b/os/io.c
> index 922a8eb..3e56fc2 100644
> --- a/os/io.c
> +++ b/os/io.c
> @@ -102,12 +102,17 @@ typedef struct _connectionOutput {
>  static ConnectionInputPtr AllocateInputBuffer(void);
>  static ConnectionOutputPtr AllocateOutputBuffer(void);
>  
> -/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
> +/* If EAGAIN and EWOULDBLOCK are distinct errno values, then we check errno
> + * for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
>   * systems are broken and return EWOULDBLOCK when they should return EAGAIN
>   */
>  #ifndef WIN32
> -#define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
> -#else                           /* WIN32 The socket errorcodes differ from the normal errors */
> +# if (EAGAIN != EWOULDBLOCK)
> +#  define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
> +# else
> +#  define ETEST(err) (err == EAGAIN)
> +# endif
> +#else   /* WIN32 The socket errorcodes differ from the normal errors */
>  #define ETEST(err) (err == EAGAIN || err == WSAEWOULDBLOCK)
>  #endif
>  
> -- 
> 1.7.9.2
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list