public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <aelder@sgi.com>
To: Bill Kendall <wkendall@sgi.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH] xfsdump: refactor exit_codestring()
Date: Fri, 26 Aug 2011 10:42:30 -0500	[thread overview]
Message-ID: <1314373350.2821.28.camel@doink> (raw)
In-Reply-To: <1313430212-20028-1-git-send-email-wkendall@sgi.com>

On Mon, 2011-08-15 at 12:43 -0500, Bill Kendall wrote:
> Simplify exit_codestring(), which maps an exit code into a string.
> Make it available to all code which includes "exit.h".
> 
> Also remove the unused type "exit_t".
> 
> Signed-off-by: Bill Kendall <wkendall@sgi.com>

Nice simplification.

For something like this I might have done:

	switch (code) {
#define	CASE(x)	CASE EXIT_ ## x: return #x
	CASE(NORMAL);
	CASE(ERROR);
	CASE(INTERRUPT);
	CASE(FAULT);
	default:
		return "???";
#undef	CASE
	}

But I don't know how others feel about that--they
could understandably hate it.

In any case I'm taking yours just as you posted it.

Reviewed-by: Alex Elder <aelder@sgi.com>


> ---
>  common/exit.h |   12 +++++++++++-
>  common/main.c |   33 ---------------------------------
>  2 files changed, 11 insertions(+), 34 deletions(-)
> 
> diff --git a/common/exit.h b/common/exit.h
> index 276562d..ef01684 100644
> --- a/common/exit.h
> +++ b/common/exit.h
> @@ -25,6 +25,16 @@
>  #define EXIT_INTERRUPT	2	/* interrupted (operator or device error) */
>  #define EXIT_FAULT	4	/* code fault */
>  
> -typedef size_t exit_t;
> +static inline const char *
> +exit_codestring( intgen_t code )
> +{
> +	switch ( code ) {
> +	case EXIT_NORMAL:    return "EXIT_NORMAL";
> +	case EXIT_ERROR:     return "EXIT_ERROR";
> +	case EXIT_INTERRUPT: return "EXIT_INTERRUPT";
> +	case EXIT_FAULT:     return "EXIT_FAULT";
> +	}
> +	return "???";
> +}
>  
>  #endif /* EXIT_H */
> diff --git a/common/main.c b/common/main.c
> index c4d6878..5567d44 100644
> --- a/common/main.c
> +++ b/common/main.c
> @@ -100,7 +100,6 @@ static bool_t set_rlimits( void );
>  #ifdef RESTORE
>  static bool_t set_rlimits( size64_t * );
>  #endif /* RESTORE */
> -static char *exit_codestring( intgen_t code );
>  static char *sig_numstring( intgen_t num );
>  static char *strpbrkquotes( char *p, const char *sep );
>  
> @@ -2448,38 +2447,6 @@ set_rlimits( size64_t *vmszp )
>  	return BOOL_TRUE;
>  }
>  
> -struct exit_printmap {
> -	intgen_t code;
> -	char *string;
> -};
> -
> -typedef struct exit_printmap exit_printmap_t;
> -
> -static exit_printmap_t exit_printmap[ ] = {
> -	{EXIT_NORMAL,	"EXIT_NORMAL"},
> -	{EXIT_ERROR,	"EXIT_ERROR"},
> -	{EXIT_INTERRUPT,"EXIT_INTERRUPT"},
> -	{EXIT_FAULT,	"EXIT_FAULT"}
> -};
> -
> -static char *
> -exit_codestring( intgen_t code )
> -{
> -	exit_printmap_t *p = exit_printmap;
> -	exit_printmap_t *endp = exit_printmap
> -				+
> -				( sizeof( exit_printmap )
> -				  /
> -				  sizeof( exit_printmap[ 0 ] ));
> -	for ( ; p < endp ; p++ ) {
> -		if ( p->code == code ) {
> -			return p->string;
> -		}
> -	}
> -
> -	return "???";
> -}
> -
>  struct sig_printmap {
>  	intgen_t num;
>  	char *string;



_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

      parent reply	other threads:[~2011-08-26 15:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15 17:43 [PATCH] xfsdump: refactor exit_codestring() Bill Kendall
2011-08-15 18:33 ` Christoph Hellwig
2011-08-26 15:42 ` Alex Elder [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1314373350.2821.28.camel@doink \
    --to=aelder@sgi.com \
    --cc=wkendall@sgi.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox